admin管理员组

文章数量:1122832

Currently in normal file upload process using java's HTTPUrlConnection, file is being uploaded via OutputStream and then call getResponse() to get server's response for uploaded file status.

But there is a big issue in error cases such as the requests need to be throttled or file is too large, or server is unavailable etc that client would upload the whole file and lost of bytes are wasted. In this case, we need client to stop the upload early, the ideal case is client to listen to server's response during uploading file.

But seems like the HTTPsUrlConnection or some libraries like OkHttp is not able to handle this, maybe due to the HTTP protocol limitations.

I have couple of options.

  1. Call to get response with 1xx before uploading a file - but it still will have error during upload and waste byte.
  2. Chunk uploads, seems like this is how Google is doing for uploading file to cloud, where each chunk can be requested separately and call the response code from server.
  3. Switch to other protocol, like websocket.

Wondering is there any other recommendations that I am missing? Or any feedbacks on existing options. Thanks!

本文标签: androidHTTPclient able to stop uploading file while getting server responseStack Overflow