两台服务器之间的java传输InputStream
我有以下代码,它接受InputStream
并将其发送到另一台服务器:
Client client = ClientBuilder.newClient();
MultipartBody mpb = new MultipartBody(
new Attachment(
"file",
uploadedInputStream,
new ContentDisposition("file=test.pdf")
)
);
Response response = client.target(url)
.request(APPLICATION_JSON)
.post(Entity.entity(mpb, MediaType.MULTIPART_FORM_DATA_TYPE), Response.class);
在第二台服务器中,我有一个api:
public String uploadFile(
@Context HttpServletRequest request,
@PathParam("name") String fileName,
@PathParam("type") int type,
@PathParam("userIdentifier") String userId,
@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail
)
{
return null;
}
我得到了错误400
当我取出InputStream
和FormDataContentDisposition
的@FormDataParam
时
一切都很好,我得到了成功的回应
# 1 楼答案
所以,我没有找到任何解决方案,所以我没有将文件作为附件发送,而是将其作为字节发送。 我就是这样做的:
第一台服务器:
接收文件的第二个: