wbstr / vaadin-multifileupload

12 stars 23 forks source link

Progress indicator not shown for first uploaded file for multiple mode #32

Open bgeagle opened 8 years ago

bgeagle commented 8 years ago

Progress indicator not shown for first uploaded file for multiple mode

In multiple mode progress indicator is not shown when first file is uploaded and it takes more time. After processing first file, during processing next file, progress indicator is shown correctly.

Tested for Vaadin 7.6.4 and 7.5.10.

juger89 commented 8 years ago

I can't reproduce this. What type and version of browser have you tested? Are you using Push or Poll to refresh the UI? Can you send a sample code?

bgeagle commented 8 years ago

Sorry for late answer…

We don't use Push or Poll (standard Vaadin's configuration), actually I haven't realized we should (it would be more clear to mention this in docs). Up to now we haven't need to do so... and I'm worried about increased requirements for Internet connection parameters (much more request for Poll or open network sockets for Push). We don't require any sophisticated monitoring of upload process, we just need to see if there is an active connection to server (the standard loading indicator at the top of the window), and an update after file upload finished.

I have made some tests. I used the latest Vaadin version 7.7.3, Firefox 49.0.1, Chrome 53.0.2785.143 m. I tested two projects - let's call it Demo and Original:

Demo - based on the simplest vaadin maven artifact:

Original - based on the original vaadin-multifileupload source code with some modifications:

When multiple mode is turned off everything works fine – the loading indicator appears and the UI is updated after upload finished - the single mode forces UI update at the beginning and after end of upload (Demo and Original). When multiple mode is turned on and a single file is uploaded, the User doesn't see any changes (both the indicator and the result after upload) until next UI synchronization eg. button click (Demo and Original). When more than 2 files are uploaded, the loading indicator is show after 2-nd file upload started (Demo and Original), but usually the result of last uploaded file is not shown (Demo and Original in Firefox, Chrome OK).

It seams that UI synchronization is done at the beginning of each uploaded file except the first one and there is no synchronization after last file upload finished. Forcing missing UI synchronization for the first file and after the last file would resolve the problem.

I have made some source code investigation:

  1. ApplicationConnection#sendPendingVariableChanges is deprecated and it's behaviour have changed since Vaadin 7.6. The current code calls ServerRpcQueue.flush() and does nothing if there is no changes at client side (ServerRpcQueue is empty), so calling sendPendingVariableChanges (or ServerRpcQueue.flash()) a few times have no effect. Previously it could be used as a substitute of a serverPool call.
  2. So the call client#sendPendingVariableChanges() in VmultiUpload#postNextFileFromQueue usually have no effect, especially for the first uploaded file
  3. And the only reliable UI synchronization is done by the client.updateVariable(paintableId, "ready", true, true); call in VmultiUpload#readyStateChangeHandler (this is not called after last file uploaded)

A possible solution would be:

  1. Force some variable change after start of each uploaded file – call client.updateVariable in VmultiUpload#postNextFileFromQueue instead of call client#sendPendingVariableChanges, see VUpload#startUploadCmd
  2. Force poll after last file upload, see Vupload#onSubmitComplete - UploadServerRpc#poll

I have made some test with calling client.updateVariable for both cases and it seams to be OK.

Shirkamdev commented 7 years ago

I've been using MultiFileUpload, and I have realized that trying to upload a single file, by button, in multi mode, does not fire the upload complete event, so, I can't know when it finishes. Only after some UI refresh it is fired.

I have dug around the code, and I've come to the idea that this is caused by the same problem @bgeagle is referring up there.

I have tested this with Vaadin 7.7.6.

PD: I would like to continue using this extension, but I need this bugfix to be released, or I will be forced to find something else.