Play 2.0 How to Post MultipartFormData using WS.url or WS.WSRequest

后端 未结 6 1321
小蘑菇
小蘑菇 2021-02-08 22:42

In Java Http request, we can do this to make multipart HTTP POST.

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);

FileBo         


        
6条回答
  •  抹茶落季
    2021-02-08 23:33

    The accepted answer didn't work with play 2.5. Also the answer in play 2.6 documentation didn't work for 2.5.
    The below worked fine:

    Http.MultipartFormData.FilePart part = new Http.MultipartFormData.FilePart("fileKey",
                    "abc.zip", "multipart/form-data",
                    FileIO.fromFile(new File("/home/testData/abc.zip")));
    List>> data = Arrays.asList(part);
    Http.RequestBuilder requestBuilder = AuthFakeRequest.getAuthFakeRequest(routes.MyController.uploadZip()).method(POST)
                    .bodyMultipart(data, mat);
    Result result = route(app, requestBuilder);
    

    For mat and app objects they are obtained when inheriting play.test.WithApplication class.

提交回复
热议问题