Why doesn't my onsubmit callback work in Linux? - linux

I have created a file upload system which allows the user to
upload .txt,.xls and .csv formats.When I executed in windows it is
running fine but now when I deployed the application in linux(Debian)
using tomcat server I am facing this issue:
The onsubmit method is called for all the file formats.
onSubmitComplete method is called only when text files are uploaded.I
want to use onSubmitComplete event as I am using progress bar and
wanted to perform necessary action on this event.
Here is my code:
file = new FileUpload();
form = new FormPanel();
file.setName("file");
file.setTitle("select a file");
submit = new Button("Upload");
submit.setTitle("upload file");
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
submit.addClickHandler(this);
form.addSubmitHandler(this);
form.addSubmitCompleteHandler(this);
}
Please tell me why the same code is working fine in windows and not in
linux.

It was resolved as it was not platform dependency it was browser dependency.I now installed google chrome and now it is running fine in linux.

Related

Node Js--Child_process exec/execFile/Spawn is not opening exe/bat file after deployment from angular application

Here the requirement is to open the exe file from browser on button click.
This is the internal application, so client(angular) and server(node.js) is present in all machines, so here the idea is that, on button click I'm hitting node.js through socket.io and launching the exe by using node.js--child_process.
The above functionality is working fine, in my dev machine, on button click node-js is launching exe successfully, but after deployment (with dist files) it is not opening exe, and also there is no errors
This is my code
const { execFile } = require('node:child_process');
execFile('C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe', [], (error, stdout, stderr) => {console.log(error)});
Here my question is, Any config I need to change from node.js side to make it work with deployment files or is there any way to achieve this functionality in nodejs/angular?
Note:-
Even I tried to open .bat file by using spawn to trigger the exe, it is working fine in my dev-machine, but not working after deployment.
Thanks in Advance!

Uploading a file with Nightwatch and Browser Stack / Selenium Grid

I'm trying to upload a file in a nightwatch test that is being run on Browserstack in IE11. Here is what I have:
browser.execute(function (data) {
const el = document.querySelector('input#fileUpload');
el.style.display = "block";
el.removeAttribute('multiple');
}, []);
browser.setValue('input#fileUpload', require('path').resolve(__dirname + '/upload-files/test-doc.pdf'))
The error is a file not found issue, it works fine when being run on Chrome locally. Searching around, it seems like I need to upload the file to BS first, I found this gist and this PR but neither worked for me.
Since the file is not present on the machine of BrowserStack you might be encountering this error. You will need to use the 'setFileDetector' method provided by Selenium to upload a local file to remote grid. More details can be found on their documentation here - https://www.browserstack.com/automate/node#enhancements-uploads-downloads

How to handle data import and export from a Windows Universal app

I am developing a Windows Universal app that collects results of races. It saves each race result in a sql-lite database in an application folder so the user can view previous results. I have further requirements, however, for saving and opening race results.
I need to be able to export the results of a race as a CSV file so that they can be opened by a third-party application that might be running on a separate machine on a different operating system.
I need to be able to export the results as an HTML file that can be uploaded/included in the user's own web site.
I need the user to be able to print the results (which I was thinking could just be done by printing the HTML file from a browser)
I would like the user to be able to choose to import the results of a race created by my own legacy application in my own format.
It seems, however, that we are restricted in a Windows Universal app to saving files to just very specific folders under very specific circumstances if we have requested that app capability. Therefore I am getting access denied errors both saving and reading files using the FileOpenPicker and FileSavePicker.
I think I probably need to view the export and import of results in a different way, but after a lot of searching I have not been able to come up with the right and recommended solution to this. So the question is how should I be handling the import and export of results? Should I be using the user's documents folder, or their OneDrive? Do I need to create a web application for my app so that the user can store results in the cloud and download them from there?
CSV and HTML are both text files with some encoding. So your question is about how to read/write files with JS.
Here is example how to create html page with FileSavePicker:
var savePicker = new Windows.Storage.Pickers.FileSavePicker();
savePicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.documentsLibrary;
savePicker.fileTypeChoices.insert("Web page", [".html"]);
savePicker.suggestedFileName = "New page";
savePicker.pickSaveFileAsync().then(function (file)
{
if (file) {
var _WriteThis="<!DOCTYPE html>" + "\r\n";
_WriteThis = _WriteThis + "<html><head><title>Web page title</title>" + "\r\n";
// .....
Windows.Storage.FileIO.writeTextAsync(file, _WriteThis, Windows.Storage.Streams.UnicodeEncoding.utf8);
}
});
This example doesn't required any special rules and you can save file anywhere on you PC HDD or USD stick without setting capabilities in manifest (except system folders)
Same way you can save in csv format

ios8 Core Data iCloud Today Widget not synchronizing

I have been unsuccessful in getting core data to work on an app and today widget on my device.
let url = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.mygroup.name").URLByAppendingPathComponent("fileName.sqllite")
var error: NSError? = nil
let options = [NSMigratePersistentStoresAutomaticallyOption: true,
NSInferMappingModelAutomaticallyOption: true,NSPersistentStoreUbiquitousContentNameKey:"SharedContainerName"
]
let s = coordinator?.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: options
, error: &error)
I have added a group container that I use for the URL of the stores. I have noticed on the simulators that my persistent coordinator points to the same sqllite file
(URL: file:///Users/xxxx/Library/Developer/CoreSimulator/Devices/6Cxxxxxx/data/Containers/Shared/AppGroup/E65xxxxxx/fileName.sqllite))
This seems to work fine on the simulator and I can store data in my main app and fetch it in today widget. When I run the code on my device the files are at different locations and the databases are not synchronized (no data on the today widget).
My Main App
(URL: file:///private/var/mobile/Containers/Shared/AppGroup/2CCXXX/CoreDataUbiquitySupport/mobile~F74XXX/SharedContainerName/0E8XXXX/store/fileName.sqllite))
Today Widget
(URL: file:///private/var/mobile/Containers/Shared/AppGroup/2CCXXX/CoreDataUbiquitySupport/mobile~F74XXX/SharedContainerName/2FBYYYY/store/fileName.sqllite))
I am assuming this should be fine as they should be synchronized by iCloud. The widget runs fine, however it has no data (like it has not been synchronized). Now debugging this has been tricky as I am unable to get console output while running the today widget. When I run the widget from Xcode as opposed to attaching to the running process (The only way I can get any output on the console) I receive an error core data iCloud: Error: initial sync notification returned an error BRCloudDocsErrorDomain error 12. I receive no notifications. Maybe iCloud and Core Data do not work at this time with a today widget? The core data code in my app and extension are identical so I do not think I have a bug.
According to this Apple Developer Forum message from an Apple employee:
None of iCloud is accessible from within an Extension in iOS 8.0
and he adds in another message:
Document syncing, I should clarify, or anything which requires file coordination. I'm not sure about KVS or CloudKit
The recommendation is to expose the application state to extensions using some other method (plist, separate files, etc), which is a bit of a bummer.

Uploaded image only available after refreshing the page

When I upload a picture, the file is successfully saved and the path is successfully set. But the uploaded image is not displayed immediately after the form submit. Only when I reload the page, the uploaded image is displayed.
I'm saving the uploaded file as below:
InputStream is;
try {
File file = new File("C:\\****\\*****\\Documents\\NetBeansProjects\\EventsCalendary\\web\\resources\\images\\uploadPhoto.png");
is = event.getFile().getInputstream();
OutputStream os = new FileOutputStream(file);
setUserPhoto("\\EventsCalendary\\resources\\images\\"+file.getName());
byte buf[] = new byte[1024];
int len;
while ((len = is.read(buf)) > 0) {
os.write(buf, 0, len);
}
os.close();
is.close();
} catch (IOException ex) {
System.out.println(ex.getStackTrace());
}
Why is the uploaded image only displayed after reloading the page and how can I solve this?
You're writing the file straight into the IDE's project folder and your intent seems to save the file in the webapp's deploy folder. This is a bad idea and well due to the following 3 main reasons:
Changes in the IDE's project folder does not immediately get reflected in the server's work folder. There's kind of a background job in the IDE which takes care that the server's work folder get synced with last updates (this is in IDE terms called "publishing"). This is the main cause of the problem you're seeing.
In real world code there are circumstances where storing uploaded files in the webapp's deploy folder will not work at all. Some servers do (either by default or by configuration) not expand the deployed WAR file into the local disk file system, but instead fully in the memory. You can't create new files in the memory without basically editing the deployed WAR file and redeploying it.
Even when the server expands the deployed WAR file into the local disk file system, all newly created files will get lost on a redeploy or even a simple restart, simply because those new files are not part of the original WAR file.
You need to write it to a fixed path outside the project/deploy folder instead. For example, /var/webapp/uploads. Then, to get it to be served by your webapp, just add it as a new web application context to the server.
Based on your previous question, I know that you're using Glassfish 3.1. In this server, it's called a "virtual host". You can configure it at server level in the admin console at http://localhost:4848 > Configuration > HTTP Service > Virtual Servers, or at webapp level by adding the following line to the /WEB-INF/glassfish-web.xml (your IDE should have autogenerated one; note that this file is before Glassfish 3.1 called sun-web.xml, so if you're seeing manuals/blogs/tutorials referencing it, yes it's exactly the same file):
<property name="alternatedocroot_1" value="from=/uploads/* dir=/var/webapp" />
Either way, you should then be able to use http://localhost:8080/contextname/uploads/* to serve those uploaded images from by <img> the usual way.
See also:
How to upload files to server using JSP/Servlet?
Recommended way to save uploaded files in a servlet application (contains a Tomcat configuration example)
Reading/writing a text file in a servlet, where should this file be stored in JBoss? (contains JBoss configuration example)
Simplest way to serve static data from outside the application server in a Java web application

Resources