Kurirux Kurirux - 21 days ago 5
Java Question

play framework file upload

I'm trying to add file uploading handling in play framework app to existing form with text field.
According to documentation, I need to use

asMultipartFormData()
or
asRaw
method, however, it can not handle text input fields. Is it possible to use one controller for standart html form and file processing at the same time?

Answer

Yes, it is possible, just simply handle file and text input separately. For instance:

public Result myControllerMethod(){
  ...
  //handle input text here
  Form<MyModel> myForm = formFactory.form(MyModel.class);
  MyModel myModel = myForm.bindFromRequest().get();
  ...
  //handle file
  MultipartFormData<File> body = request().body().asMultipartFormData();
  ...
}