简体   繁体   中英

How to implement folder upload in a Spring web app?

I'd like to implement in my web application a file/directory upload similar to Google Drive style (I think it's the best example to explain what I want).

So I would like to upload:

  • a single file
  • multiple selected files
  • a selected folder (all files contained in it)

On client side I suppose I have to use HTML5, am I wrong? But How to handle this on server side controller. I'm using Spring MVC 3.2.9

Can you suggest me the best approach?

The hard part is the client side upload of folders. According to this other answer on SO about Does HTML5 allow drag-drop upload of folders or a folder tree? , The HTML5 spec does NOT say that when selecting a folder for upload, the browser should upload all contained files recursively .

Of course it is possible, but HTML5 is not enough and you will have to use Javascript to (recursively) find all files in the folder.

As said by conFusl, you can find a nice example on viralpatel.net Spring MVC Multiple File Upload tutorial. Spring Multiple File upload example . The princips are :

  • on client side generate (via javascript) a form with one <input> tag per file to upload, and give them names like files[i]
  • on server side, you then get a form containing a List<MultipartFile> that you can process as usual.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM