2

如何从 MultipartFormData 中获取 DataPart?我找不到任何 API 来获取它。

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");
4

2 回答 2

14

我不习惯在 Play 2.0 中使用 Java,但这样的工作是否可行?

@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());
}
于 2012-06-04T07:16:56.710 回答
5

在斯卡拉:

def index = Action(parse.multipartFormData) {
    request => {

     val dataKey = request.body.dataParts.get("dataKey")
     something something...

     Ok("Ok!")
}
于 2013-05-10T13:37:23.693 回答