0

I am trying to upload a file to cloud using jersey client. But here I am getting below response.

InboundJaxrsResponse{context=ClientResponse{method=POST, uri=http://test.net/hello, status=400, reason=400}}

and the source is as below.

    final Client client = ClientBuilder.newBuilder().register(MultiPartFeature.class).build();
final JsonObjectBuilder formJson = Json.createObjectBuilder();
formJson.add("name", fileName);
formJson.add("parent", 0);
String jsonStr = formJson.build().toString();

final FileDataBodyPart filePart = new FileDataBodyPart("file", new File(fileLocation));
FormDataMultiPart formDataMultiPart = new FormDataMultiPart();

final FormDataMultiPart multiPart = (FormDataMultiPart) formDataMultiPart   
        .field(jsonStr, MediaType.MULTIPART_FORM_DATA).bodyPart(filePart);
    multiPart.setContentDisposition(FormDataContentDisposition.name("file").fileName(fileLocation).build());
final WebTarget target = client.target("http://test.net/hello");
final Response response = target.request().header("Content-Type", "multipart/form-data")
                    .header("instanceid", "b05642c8-d231-48fe-a163-d978a6208d98")
                    .post(Entity.entity(multiPart, "multipart/form-data"));

Can any one help me to out this issue.

Thanks,

iOS
  • 11,881
  • 4
  • 71
  • 92
  • Can you inspect the request and see if the Content-Type header has an added [boundary](https://stackoverflow.com/questions/3508338/what-is-the-boundary-in-multipart-form-data). If not, try and use `multiPart.getMediaType()`, instead of the static `"multipart/form-data"`. – Paul Samsotha Feb 28 '19 at 00:15
  • Also are you using any different [transport connector](https://jersey.github.io/documentation/latest/client.html#d0e4971), aside from the default one? – Paul Samsotha Feb 28 '19 at 00:16
  • You might also want to read the body of the response to see if there is any helpful error message? – Paul Samsotha Feb 28 '19 at 00:17
  • mediatypa is added into header and also I am using default connector only. – mounish Feb 28 '19 at 01:10
  • I didn't ask mnediatype, I asked "boundary". And also did you look at the response body? – Paul Samsotha Feb 28 '19 at 01:18
  • {Content-Type=[multipart/form-data], Content-Disposition=[form-data; filename="Application_20190228070500.xlsx"; modification-date="Thu, 28 Feb 2019 01:35:00 GMT"; size=3469; name="file"]}, boundary not there. – mounish Feb 28 '19 at 01:39

0 Answers0