Upload multiple files at once using GWT-Collection of common programming errors
The solution is pretty simple. gwt-upload has a class Uploader which is able to do multiple uploads. The servlet code suggested in the wiki of gwt-upload is already capable of handling multiple uploads.
I had to change somethings in the Uploader class (source is fully available, so I just copied it and replaced the parts I needed). To access filenames and filesizes of the selected files I created a simple native method:
private static native String getFilesSelected() /*-{
var count = $wnd.$('input:file')[0].files.length;
var out = "";
for (i = 0; i < count; i++) {
var file = $wnd.$('input:file')[0].files[i];
out += file.name + ';' + file.size + ";";
}
return out;
}-*/;
whichs return value I split by ; to get the needed results.
And you need to replace the uploaders FileInput (setFileInput()) with a custom one, which sets the multiple property to the input. I use a wrapper class like this:
public class MyFileInput implements IFileInput {
private final FileUpload fu;
public MyFileInput() {
fu = new FileUpload();
DOM.setElementProperty(fu.getElement(), "multiple", "multiple");
}
}
you obviously need to implement the other methods of IFileInput, I linked them all through to fu. Two had no equivalent method, but I dont use them, so no problem here …
Originally posted 2013-11-09 19:45:05.