How to implement HTTP Post chunked upload of a big

2020-05-08 06:54发布

I have an enormous file to upload and server 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?

2条回答
Lonely孤独者°
2楼-- · 2020-05-08 07:17

Using HttpURLConnection, just set chunked transfer mode.

查看更多
beautiful°
3楼-- · 2020-05-08 07:26

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.

查看更多
登录 后发表回答