davioooh
davioooh

Reputation: 24666

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:

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?

Upvotes: 2

Views: 5098

Answers (1)

Serge Ballesta
Serge Ballesta

Reputation: 148880

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.

Upvotes: 2

Related Questions