2

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?

davioooh
  • 23,742
  • 39
  • 159
  • 250
  • At the upload time check if the select file is file or directory. If file upload it, if directory scan all files in it, upload them along with name of directory which is created and files are saved in them. – Darshan Lila Sep 17 '14 at 08:45

1 Answers1

2

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.
Community
  • 1
  • 1
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252