Skip to content

Instantly share code, notes, and snippets.

@Shiti
Last active December 10, 2015 09:29
Show Gist options
  • Save Shiti/4414239 to your computer and use it in GitHub Desktop.
Save Shiti/4414239 to your computer and use it in GitHub Desktop.
Example function to handle a form with image and other fields in Play Scala
def addProfile = Action(parse.multipartFormData) {
request =>
val formData = (request.body).asFormUrlEncoded
val email = formData.get("email").get(0)
val name = formData.get("name").get(0)
val userId = User.create(User(email, name))
request.body.file("displayPic").map {
picture =>
val fileName = businessId
val path="/socialize/user/"
if (picture.filename.length > 0) {
picture.ref.moveTo(new File(path+fileName+".jpeg"))
}
Ok("successfully added user")
}.getOrElse{
BadRequest("failed to add user")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment