2

in Playframework 2.2, it is possible to bind an entity from request like so:

Form<EntityA> form = form.bindFromRequest();
EntityA entity = filledForm.get();

It seem to work for String values but it doesn't seem to work when I have a file in the entity and using the @inputFile notation.

I can read the file via multipart form data as such:

MultipartFormData body = request().body().asMultipartFormData();
FilePart picture = body.getFile("uploadedFile");

But that is not elegant because I need to read the file via multipart form data and the other fields via the bindFromRequest.

I would like to do something like this:

Form<EntityA> form = form.bindFromRequest();
EntityA entity = filledForm.get();
File file = entity.uploadedFile;

but only null gets returned when the field is a file.

How do we upload a file into a form and get it directly from the binded form and not the multipart form data?

Thank you.

Renegade
  • 33
  • 1
  • 7

1 Answers1

1

If your form contains an entity AND a file, you could solve it using this approach: How to get the upload file with other inputs in play2?

If you can manipulate the POST methid, just don't use @inputFile for the entity. Otherwise, if what you want to bind is the @inputFile itself, you will need to use any marshalling/unmarshalling method.

Community
  • 1
  • 1
Didac Montero
  • 2,046
  • 19
  • 27