File upload along with other object in Jersey restful web service

后端 未结 6 1803
忘掉有多难
忘掉有多难 2020-11-22 13:34

I want to create an employee information in the system by uploading an image along with employee data. I am able to do it with different rest calls using jersey. But I want

6条回答
  •  鱼传尺愫
    2020-11-22 13:58

    I want add a comment on peeskillet but don't have 50 reputation points, hence adding as an answer:

    When I tried @peeskillet solution with Jersey client 2.21.1, there was 400 error. It worked when I added following in my client code:

      MediaType contentType = MediaType.MULTIPART_FORM_DATA_TYPE;
      contentType = Boundary.addBoundary(contentType);
    
      Response response = t.request().post(
            Entity.entity(multipartEntity, contentType));
    

    instead of hardcoded MediaType.MULTIPART_FORM_DATA in post request call.

提交回复
热议问题