0

When the user uploads a single file we will be retrieving the file as follows

play.mvc.Controller.request().body().asMultipartFormData().getFiles().get(0)

When the user selects and uploads multiple files we will be retrieving the multiple files as follows and process one by one

play.mvc.Controller.request().body().asMultipartFormData().getFiles()

Now we need to allow the user to upload a folder which will have files, sub-folder and sub-folder may contain multiple files or folders. We need to process them all.

Example, in FileZilla an user can upload an entire folder and the folder, sub-folder, sub-folder and all files will be uploaded to the server.

Need help on the following

  1. How to provide an option to user to upload a folder?
  2. Which Play API is used to process folder and sub-folder and files recursively in Play framework?
  3. Does folder upload supported by all browsers?
  4. Do we have any utility in play for accept bulk upload or folder upload from the client?

Currently we are using anjular 1.0 and need help on the above

Thanks.

Kathire
  • 53
  • 1
  • 8
  • You can use the `webkitdirectory=""` attribute on the input. This will allow Google Chrome to upload folders. However, this is supported only by Chrome from what I know. Inside the Java code, you should be able to process the files same as you do when multiple files are uploaded. – Ibrahim Aug 06 '16 at 12:33
  • How about other browsers? Does Chrome only Supports it? Can u please help me with a sample snippet or psuedo code assuming as folder is getting uploaded? – Kathire Aug 06 '16 at 12:53
  • Unfortunately yes, only Chrome supports it. Here is a jsfiddle with one input that has webkitdirectory set https://jsfiddle.net/dt0cbmkt/. As for Java, I don't have a project with Play framework, but try using what you said: `play.mvc.Controller.request().body().asMultipartFormData().getFiles()` – Ibrahim Aug 06 '16 at 13:06

1 Answers1

0
  1. From the client side zip the directory and upload as a single file.

  2. In play framework use java.util.zip to unzip the file and process. This is not a Play or Scala feature, but one from Java.

    See: JSZip

    See: How to unzip a zip file using scala?

    See: How do I list all files in a subdirectory in scala?

Community
  • 1
  • 1
Dun
  • 11
  • 1
  • 3
  • Thanks, Darel. I would like to know whether processing the folder as zip is a best practise or processing folder itself is the best practice as chrome and firefox supports folder upload. Also, could you please help me on how to list all the files in a subdirectory in Play Java instead of Scala – Kathire Aug 07 '16 at 16:01