Vaadin 7: Uploading large files in background thread

50 views Asked by At

In Vaadin 7 (or Vaadin 8, I suppose), how do we upload files in a background thread, using Vaadin Upload component? The Vaadin documentation has examples of using the progress bar, but no examples of actually uploading in another thread. In my case, it is locking the Vaadin session for my browser until the file is uploaded. If I could do it in a background thread, I could get around the issue.

I set all the listeners in the Upload component, and I can do other things in the background just fine, I just don't even know where to start to do the actual upload in the background. I even see an example online for processing the file in the background, I just don't see an example for uploading a file in the background.

My goal is to run it in another thread so the Vaadin session as a whole is not locked (thus enabling me to use other browser tabs for the same website, for instance).

Here are some logs where we potentially see locking DURRING the upload. It is not perfect, but it is suggestive.

[2024-01-31 13:33:23 EST] INFO com.mobiwms.website.view.upload.CsvFilesComponent uploadStarted Starting upload of file [January1.0B.csv], session locked? true
[2024-01-31 13:33:23 EST] INFO com.mobiwms.website.view.upload.CsvFilesComponent receiveUpload Uploading file January1.0B.csv, mime type text/csv, session locked? true
[2024-01-31 13:33:23 EST] INFO com.mobiwms.website.view.upload.CsvFilesComponent updateProgress Progress of upload, read 4096 bytes, out of 345369, session locked? true
[2024-01-31 13:33:23 EST] INFO com.mobiwms.website.view.upload.CsvFilesComponent updateProgress Progress of upload, read 345369 bytes, out of 345369, session locked? true
[2024-01-31 13:33:23 EST] INFO com.mobiwms.website.view.upload.CsvFilesComponent uploadSucceeded Succeeded in uploading of file [January1.0B.csv], session locked? true
[2024-01-31 13:33:54 EST] INFO com.mobiwms.website.view.upload.CsvFilesComponent openFile Openning file [January1.0B.csv], session locked? true
[2024-01-31 13:33:54 EST] INFO com.mobiwms.website.view.upload.CsvFilesComponent uploadFinished Finished upload of file [January1.0B.csv], session locked? true

As you can see, VaadinSession.getCurrent().hasLock() returns true much of the way through the process. I suppose these "upload" methods could be triggered during times where the session is locked, but the "opening file" log is before I start a thread to open the file locally. I actually thought it would be false there, but it was true. Granted, so far hasLock always returns true, but that could be only because I happen to be checking it at the wrong time. If anyone thinks it would be helpful to find such a place, and can point me in such a place, I can add the corresponding log.

0

There are 0 answers