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

Advertisements

2 thoughts on “Playing MultipartFormData: A basic example to handle and test MultipartFormData request in Play Framework 2.3.8

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s