Play 2 How to get DataPart from MultipartFormData

playframework-2.0

Solution

I'm not used to work with Java in Play 2.0, but is something like that working ?

@BodyParser.Of(BodyParser.MultipartFormData.class)
public static Result index() {
    Http.MultipartFormData multipartFormData = request().body().asMultipartFormData();

    //ask the multipart to be form url encoded... 
    //and get the data
    String[] data = multipartFormData.asFormUrlEncoded().get("dataKey");

    //which should not impact such call
    Http.MultipartFormData.FilePart image = multipartFormData.getFile("imageKey");

    return ok("Got image: " + image.getFilename());
}

Problem

How to get a DataPart from MultipartFormData? I could not find any API to get that. ``` Http.MultipartFormData formData = body.asMultipartFormData(); // simple form field // there is NO getData() or something available DataPart imageIdPart = formData.getData("dataKey"); // uploaded file FilePart imagePart = formData.getFile("imageKey"); ```

Original source