I am new to Gwt. I use the standard FileUpload component. How to make so that the user can select several files at once and upload them to the server?

    2 answers 2

    I advise you to analyze the demo using the developer window (see the code of the elements).

    The FormPanel class expands to a <form> element. And the FileUpload class unfolds into an element.

    <input type="file"> 

    In the example there are several form & input (file) pairs. They are not visible from the outside, the user is pushed by another UI. Therefore, to implement this with the help of GWT, you need to have several FileUpload & FormPanel pairs and a list of already uploaded files (on VerticalPanel, for example). Each time a user selects a new file, we will add another FileUpload & FormPanel pair and substitute the user for a new click, which does not yet have a value, input. Then, when the user clicks OK, we send all of our forms (FormPanel) sequentially. Then we listen to SubmitCompleteEvent, and when it comes N times (the number of files), then we can assume that we have zapoladadili all files.

    We cannot select several files at once and send them. That is, in order for us to select several files in the dialog, we need to write only one perper, but only the first file will be sent. And, in my opinion, it is impossible to make the form work differently. To do this, you must use the action script.

      For these purposes, we use GWT Upload in our project. The library has a class of MultipleUploader, which allows the user to select several files in turn: while the first file is sent, the second is in the queue.

      As for the simultaneous selection of several files and sending them in one request - I think this is possible. Try changing the GWT Upload source code to your needs, we do this so often.

      As for transferring files to multiple requests, be careful, because the browser allows the programmer to establish only two connections to the server. If you ignore this rule, Internet Explorer may hang.

      • one
        @Ivan Golubev I think about the choice of several files and sending them with one request you are wrong. - angry