I am using Jersey client for http-based request. It works well if the file is small but run into error when I post a file with size of 700M:
Exception in thr
In order for your code not to depend on the size of the uploaded file, you need:
client.setChunkedEncodingSize(1024);
Server:
@POST
@Path("/upload/{attachmentName}")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public void uploadAttachment(@PathParam("attachmentName") String attachmentName, InputStream attachmentInputStream) {
// do something with the input stream
}
Client:
...
client.setChunkedEncodingSize(1024);
WebResource rootResource = client.resource("your-server-base-url");
File file = new File("your-file-path");
InputStream fileInStream = new FileInputStream(file);
String contentDisposition = "attachment; filename=\"" + file.getName() + "\"";
ClientResponse response = rootResource.path("attachment").path("upload").path("your-file-name")
.type(MediaType.APPLICATION_OCTET_STREAM).header("Content-Disposition", contentDisposition)
.post(ClientResponse.class, fileInStream);