I'm trying to implement file upload using the Play Framework 2 (Java)
To do this, I've followed the following guide: http://www.playframework.org/documentation/2.0/JavaFileUpload
On the server-side, I always get an object of MissingFilePart in the MultipartFormData.
This is my view:
@form(action = routes.ImmediateCollections.savePoliceReport, 'enctype -> "multipart/form-data") {
<fieldset>
<div class="fileupload fileupload-new">
<span class="btn btn-file">
<span class="fileupload-new">Select file</span>
<span class="fileupload-exists">Change</span>
<input type="file" name="policeReportFile" id="policeReportFile"/>
</span>
<span class="fileupload-preview"></span>
<a href="#" class="close fileupload-exists" style="float: none">×</a>
</div>
</fieldset>
@controls {
@submitbutton()
}
}
This generates the following html:
<form action="/immediatecollections/save-policereport" method="POST" enctype="multipart/form-data">
<fieldset>
<div class="fileupload fileupload-new">
<span class="btn btn-file">
<span class="fileupload-new">Select file</span>
<span class="fileupload-exists">Change</span>
<input type="file" name="policeReportFile" id="policeReportFile">
</span>
<span class="fileupload-preview"></span>
<a href="#" class="close fileupload-exists" style="float: none">×</a>
</div>
</fieldset>
<div class="control-group">
<div class="controls">
<input type="submit" class="btn btn-success" value="Save">
</div>
</div>
</form>
(For those wondering about the spans and divs, I'm using the excellent jasny bootstrap extensions.)
Note that I only have one input field. This form only serves one purpose: uploading 1 file.
This is my controller :
public static Result savePoliceReport() {
Http.MultipartFormData formData = request().body().asMultipartFormData();
Http.MultipartFormData.FilePart policeReportFile = formData.getFile("policeReportFile");
if (policeReportFile != null) {
// move file to somewhere
// save metadata to database
// for simplicity's sake: return json success = true or false
ObjectNode jsonResult = Json.newObject();
jsonResult.put("success", true);
return ok(jsonResult);
} else {
ObjectNode jsonResult = Json.newObject();
jsonResult.put("success", false);
return badRequest(jsonResult);
}
}
This method is defined like this in the routes file:
POST /immediatecollections/save-policereport controllers.ImmediateCollections.savePoliceReport
Now when I upload a file and debug on the server-side, this is what I get as request:

If I'm reading this correctly, it says the file contents are missing. What happened? Did the bytes get lost in transmission? Why didn't Play throw an exception if something failed?
I've tried this in both Chrome and Internet Explorer, with both times the same result.
What am I doing wrong? Thanks!