{"id":481,"date":"2022-08-30T15:02:04","date_gmt":"2022-08-30T15:02:04","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/upload-multiple-files-at-once-using-gwt-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:02:04","modified_gmt":"2022-08-30T15:02:04","slug":"upload-multiple-files-at-once-using-gwt-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/upload-multiple-files-at-once-using-gwt-collection-of-common-programming-errors\/","title":{"rendered":"Upload multiple files at once using GWT-Collection of common programming errors"},"content":{"rendered":"<p>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.<\/p>\n<p>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:<\/p>\n<pre><code>private static native String getFilesSelected() \/*-{\n    var count = $wnd.$('input:file')[0].files.length;\n\n    var out = \"\";\n\n    for (i = 0; i &lt; count; i++) {\n        var file = $wnd.$('input:file')[0].files[i];\n        out += file.name + ';' + file.size + \";\";\n    }\n    return out;\n}-*\/;\n<\/code><\/pre>\n<p>whichs return value I split by ; to get the needed results.<\/p>\n<p>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:<\/p>\n<pre><code>public class MyFileInput implements IFileInput {\n\n    private final FileUpload fu;\n\n    public MyFileInput() {\n        fu = new FileUpload();\n        DOM.setElementProperty(fu.getElement(), \"multiple\", \"multiple\");    \n    }\n}\n<\/code><\/pre>\n<p>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 &#8230;<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 19:45:05. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-481","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=481"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/481\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}