Play 2 How to get DataPart from MultipartFormData

前端 未结 2 1730
别跟我提以往
别跟我提以往 2021-01-22 06:06

How to get a DataPart from MultipartFormData? I could not find any API to get that.

Http.MultipartFormData formData = body.asMultipartFormData();

// simple form         


        
2条回答
  •  天命终不由人
    2021-01-22 06:43

    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());
    }
    

提交回复
热议问题