Play 2 How to get DataPart from MultipartFormData

前端 未结 2 1699
别跟我提以往
别跟我提以往 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:42

    In scala:

    def index = Action(parse.multipartFormData) {
        request => {
    
         val dataKey = request.body.dataParts.get("dataKey")
         something something...
    
         Ok("Ok!")
    }
    
    0 讨论(0)
  • 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());
    }
    
    0 讨论(0)
提交回复
热议问题