Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8236657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:12:11+00:00 2026-06-07T19:12:11+00:00

According to this guide , one can upload files by writing the html form

  • 0

According to this guide, one can upload files by writing the html form by hand. I want to handle file upload as part of a bigger form that includes text fields (for example name and email). Here is what I have to far (quite ugly):

def newUser = Action(parse.multipartFormData) { implicit request =>{   
    //handle file
    import play.api.mvc.MultipartFormData.FilePart
    import play.api.libs.Files.TemporaryFile

    var uploadSuccessful = true 
    var localPicture: FilePart[TemporaryFile] = null

    request.body.file("picture").map { picture =>
    localPicture = picture   }.getOrElse {
    uploadSuccessful = false   }

    //process the rest of the form
    signupForm.bindFromRequest.fold(
      errors => BadRequest(views.html.signup(errors)),
      label => {
        //file uploading code here(see guide), including error checking for the file.

        if(uploadSuccesful){
        User.create(label._1, label._2, label._3._1, 0, "NO PHOTO", label._4)
        Redirect(routes.Application.homepage).withSession("email" -> label._2)
        } else {
        Redirect(routes.Application.index).flashing(
        "error" -> "Missing file"
        }
      })
     }   }

This looks tremendously ugly to me. Note that I have defined a signupForm somewhere that includes all fields (apart from the file upload one). My question is: Is there a prettier way of going about this? Perhaps by including the file field in the signupForm and then handling errors uniformly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:12:13+00:00Added an answer on June 7, 2026 at 7:12 pm

    So far I think it’s not possible to bind binary data to a form directly, you can only bind the reference (e.g. the picture’s ID or name). You could however reformulate your code a bit:

    def newUser() = Action(parse.multipartFormData) { implicit request => 
      import play.api.mvc.MultipartFormData.FilePart
      import play.api.libs.Files.TemporaryFile
    
      request.body.file("picture").map { picture =>
        signupForm.bindFromRequest.fold(
          errors => BadRequest(views.html.signup(errors)),
          label => {
            User.create(label._1, label._2, label._3._1, 0, picture.absolutePath(), label._4)
            Redirect(routes.Application.homepage).withSession("email" -> label._2)
          }
        )
      }.getOrElse(Redirect(routes.Application.index).flashing("error" -> "Missing file"))
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to http://developer.android.com/guide/practices/screens_support.html Normal screen with hdpi can have few resolutions, like 480X800 600x1024
According to this SDK guide , unit-testing a Library project can be achieved by
I didnt find anything according this issue. Can jaas be used to secure my
According to this post in Recursive Descent vs. LALR , any LALR(k) can be
According to this forum , SSIS only supports UTF-16 Little Endian flat files. Is
According to this answer I want to create my own subclass of Array QArray
I've been trying to build live555 according to this guide: https://github.com/boltonli/ohbee/tree/master/android/streamer/jni as well as
According this article , generic JPA DAO(Data Access Object) is a pretty nice pattern.
I have made a custom suface button according this example: <Button> <Button.Template> <ControlTemplate TargetType=Button>
According to this SO post: How to check the TEMPLATE_DEBUG flag in a django

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.