Download gwt-ext file

I am trying to download a file from gwt-ext without opening a dialog. For this, I created a FormPanel and added the appropriate fields to it. Submit () form was then made. It doesn't seem to work. Any idea why? The code is shown below.

final FormPanel uploadForm = new FormPanel();
uploadForm.setVisible(false);
uploadForm.setFileUpload(true);
final TextField sourceFile = new TextField("File", "sourceFile");
sourceFile.setVisible(false);
sourceFile.setInputType("file");
sourceFile.setValue("/tmp/test.txt");

final TextField targetFile = new TextField("Upload As", "targetFile");
targetFile.setVisible(false);
targetFile.setValue("different.txt");

uploadForm.add(sourceFile);
uploadForm.add(targetFile);

final String url = GWT.getModuleBaseURL() + "/uploadFile";
uploadForm.getForm().submit(url, null, Connection.POST, null, false);

      

I have tested the server side servlet with simple html form and it works correctly. Only the GWT-EXT version doesn't work.

+1


source to share


2 answers


I found out why the above code snippet is not working. The main problem here is that file uploads are blocked by the browser due to security reasons if the upload form has not been rendered and / or if the form has been modified after the user clicks the submit button. If the browser allowed such things, then any file on the system could be easily downloaded without the user's knowledge.



The solution to this problem is to open the dialog box, load the event handler for the submit button, and in the onActionComplete method of the form listener, do any other processing.

0


source


The whole idea of ​​loading without a dialog looks like a security breach to me. I can imagine an application that steals the password file when opened, if possible.



0


source







All Articles