【发布时间】:2019-08-21 17:51:38
【问题描述】:
我需要一些帮助来使用 com.ning.http.client.AsyncHttpClient 创建一个 java 客户端,它将使用下面的其余服务上传文件
我尝试使用带有此代码的客户端,但到达服务器的 FileInput 流为空:
FilePart filePart = new FilePart("文件", file, null, null);
builder.setBody(new FileInputStream(file)); 或者 builder.addBodyPart(filePart);
服务代码是: @Path("/文件") 公共类 UploadFileService {
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(
@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail) {
//Given that I have ‘uploadedInputStream’ can I just pass this
//directly into the second call, below?
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource wr = client.resource(baseURI);
ClientResponse response = wr.type("image/*")
.entity(uploadedInputStream) //legal??
.post(ClientResponse.class);
}
}
【问题讨论】: