开发者

How to implement HTTP Post chunked upload of a big file using java httpclient?

开发者 https://www.devze.com 2023-02-15 03:16 出处:网络
I have an enormous file to upload and serv开发者_运维问答er on other side does support chunked upload.

I have an enormous file to upload and serv开发者_运维问答er on other side does support chunked upload. Is there any example of how exactly to do that? Or there is some other library which do that?


Using HttpClient 4 (From Apache)

HttpPost post = new HttpPost(url);
MultipartEntity content = new MultipartEntity(HttpMultipartMode.STRICT);

//To add parameters, use StringBody
content.addPart("param", new StringBody("value"));
content.addPart("param1", new StringBody("value1"));
content.addPart("param2", new StringBody("value2"));

//To add files, use InputStreamBody
content.addPart("source", new InputStreamBody(inputStream, mimeType, fileName)); //OR
content.addPart("source", new InputStreamBody(inputStream, mimeType));

//Finally
post.setEntity(content);

Hope this helps.


Using HttpURLConnection, just set chunked transfer mode.

0

精彩评论

暂无评论...
验证码 换一张
取 消