use of im.actor.core.api.rpc.RequestGetFileUploadPartUrl in project actor-platform by actorapp.
the class UploadTask method uploadPart.
private void uploadPart(final int blockIndex, final byte[] data, final int attempt) {
api(new RequestGetFileUploadPartUrl(blockIndex, blockSize, uploadConfig)).flatMap(r -> HTTP.putMethod(r.getUrl(), data)).then(r -> {
if (LOG) {
Log.d(TAG, "Block #" + blockIndex + " uploaded");
}
uploadCount--;
uploaded++;
reportProgress(uploaded / (float) blocksCount);
checkQueue();
}).failure(e -> {
if (e instanceof HTTPError) {
HTTPError httpError = (HTTPError) e;
if ((httpError.getErrorCode() >= 500 && httpError.getErrorCode() < 600) || httpError.getErrorCode() == 0) {
int retryInSecs = DEFAULT_RETRY;
if (LOG) {
Log.w(TAG, "Block #" + blockIndex + " upload error #" + httpError.getErrorCode() + " trying again in " + retryInSecs + " sec, attempt #" + (attempt + 1));
}
schedule(new Retry(blockIndex, data, attempt + 1), retryInSecs * 1000L);
return;
}
if (LOG) {
Log.w(TAG, "Block #" + blockIndex + " upload failure");
}
reportError();
}
});
}
Aggregations