Playing MultipartFormData: A basic example to handle and test MultipartFormData request in Play Framework 2.3.8

Knoldus

Playing MultipartFormData

The following blog and attached code represent an example to upload file using MultipartFormData request and Testing it into Play Application.

A basic example to handle and test MultipartFormData request in Play Framework 2.3.8

The standard way to upload files in a web application is to use a form with a special multipart/form-data encoding, which lets you mix standard form data with file attachment data. Please note: the HTTP method used to submit the form must be POST (not GET).


Code in action for Controller and Service


  val uploadService: UploadService

  def upload = Action(parse.multipartFormData) { implicit request =>
    val result = uploadService.uploadFile(request)
    Redirect(routes.Application.index).flashing("message" -> result)
  }
 /** * Get file from the request and move it in your location * * @param request * @return */ def uploadFile(request: Request[MultipartFormData[TemporaryFile]]): String = { log.error("Called…

View original post 245 more words