我正在尝试使用jersey客户端将文件上传到云。但是在这里,我的反应不佳。
InboundJaxrsResponse{context=ClientResponse{method=POST, uri=http://test.net/hello, status=400, reason=400}}
,来源如下。
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"));
任何人都可以帮助我解决这个问题。
谢谢