Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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")
BadRequest("failed to add user")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment