Last active
December 10, 2015 09:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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