Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are some items to consider:</p> <ol> <li><p>In your <code>.scala.html</code> file, you'll need a <strong>file upload field</strong> <code>&lt;input type="file" name="someName"&gt;</code>.</p></li> <li><p>You'll need to set the <strong>encoding type</strong> of the form as stated in the documentation: <code>'enctype -&gt; "multipart/form-data"</code>.</p></li> <li><p>You can then change your controller to to <strong>handle multipart form-data</strong>, so it looks like the one in the example. Use <code>Action(parse.multipartFormData)</code> to parse the form. I think you should then also be able to use your form with <code>systemForm.bindFromRequest</code> (<a href="http://www.playframework.com/documentation/2.0/api/scala/play/api/data/Form.html" rel="nofollow">from Form API)</a>, although I haven't tried that before.</p></li> </ol> <p><strong>Edit:</strong></p> <p>What I meant was to treat the uploaded file and the rest of the form data as <strong>separate</strong> items.</p> <p>Try changing the example form the documentation to look like this:</p> <pre><code>def upload = Action(parse.multipartFormData) { request =&gt; request.body.file("picture").map { picture =&gt; import java.io.File val filename = picture.filename val contentType = picture.contentType picture.ref.moveTo(new File("/tmp/picture")) // this is the new part val formContents = systemForm.bindFromRequest.value // now you can do stuff with `formContents` and `picture` Ok("File uploaded") }.getOrElse { Redirect(routes.Application.index).flashing( "error" -&gt; "Missing file" ) } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload