Requires OkHttp >= 2.1.0 if you need to work with multipart request bodies. Lower versions don’t report the content length for the body, but the sum of the sizes of the parts is a pretty good approximation.
// TODO: Build a request body
RequestBody body = null;
// Decorate the request body to keep track of the upload progress
CountingRequestBody countingBody = new CountingRequestBody(body,
new CountingRequestBody.Listener() {
@Override
public void onRequestProgress(long bytesWritten, long contentLength) {
float percentage = 100f * bytesWritten / contentLength;
// TODO: Do something useful with the values
}
});
// TODO: Build a request using the decorated body
Tested this and saw it go from 0 to 100 but not stop anywhere in between
Edit: not using multipart. But the code says "any request body"