In order to upload a file to server we used to use the form with multipart/form-data encoding. File upload is very easy with Play. Use a multipart/form-data encoded request to post files to the server, and then use the java.io.File type to retrieve the file object.
Let us see how we can handle the file upload within Play framework.
Writing an HTML form:
Notice that we’ve given the name “fileUpload” to our upload control.We’ll use same name in our Controller Action. We’ve created the form action as well which is uploadFile in our “Application” controller.
Now define the uploadFile action using a multipartFormData body parser.
Define the POST request in routes in order to call uploadFile action.
GET call will render the view of our application and the POST /upload will upload our file by calling the action defined above.
The Application controller.
Find the complete code here on Github