Search code examples
file-uploadvaadin8

Vaadin 8 multiupload with folder selection


I need to upload files and folders to the server while preserving the hierarchy. At the moment I am using a plugin multiFileUpload that allows you to upload multiple files at the same time, but it ignores the selected folders. I know that neither vaadin nor Html5 has a universal solution that works everywhere for uploading folders.

I'm ready to write my own solution, but climbed the Internet can't find a way to display file selection (perhaps there will a JavaScript call) but the main question - is it possible somehow to POST a request Vaadin's and upload files by way of creating subfolders in which they were?


Solution

  • You can only upload files, not folders. It's simply not doable.

    You can upload any number of files, but they won't be structured into folders.

    I see two possibilities how you could still achieve what you need if you really wanted to, even if it changes the user experience a bit:

    • Let the user upload a .zip file of his folder structure. When they upload it, you unzip it on the server side and have now access to all the files in the correct folder structure.

    • Let the user upload all his files within his folder structure. After all files have been uploaded, You display all the files in a TreeGrid where the user can recreate the original structure using Drag-and-Drop or similar.