Search in sources :

Example 1 with RequestCommitFileUpload

use of im.actor.core.api.rpc.RequestCommitFileUpload in project actor-platform by actorapp.

the class UploadTask method checkQueue.

private void checkQueue() {
    if (isCompleted) {
        return;
    }
    if (nextBlock == blocksCount && uploadCount == 0) {
        if (LOG) {
            Log.d(TAG, "Completing...");
        }
        long crc = crc32.getValue();
        if (LOG) {
            Log.d(TAG, "Src #" + crc);
            Log.d(TAG, "Closing files...");
        }
        inputFile.close();
        if (isWriteToDestProvider) {
            outputFile.close();
        }
        request(new RequestCommitFileUpload(uploadConfig, fileName), new RpcCallback<ResponseCommitFileUpload>() {

            @Override
            public void onResult(ResponseCommitFileUpload response) {
                if (LOG) {
                    Log.d(TAG, "Upload completed...");
                }
                FileReference location = new FileReference(response.getUploadedFileLocation(), fileName, srcReference.getSize());
                if (isWriteToDestProvider || alreadyInTemp) {
                    FileSystemReference reference = Storage.commitTempFile(alreadyInTemp ? srcReference : destReference, location.getFileId(), location.getFileName());
                    reportComplete(location, reference);
                } else {
                    reportComplete(location, srcReference);
                }
            }

            @Override
            public void onError(RpcException e) {
                if (LOG) {
                    Log.w(TAG, "Upload complete error");
                }
                reportError();
            }
        });
        return;
    }
    if (nextBlock < blocksCount && uploadCount < SIM_BLOCKS_COUNT) {
        loadPart(nextBlock++);
    }
}
Also used : FileSystemReference(im.actor.runtime.files.FileSystemReference) RequestCommitFileUpload(im.actor.core.api.rpc.RequestCommitFileUpload) RpcException(im.actor.core.network.RpcException) FileReference(im.actor.core.entity.FileReference) ResponseCommitFileUpload(im.actor.core.api.rpc.ResponseCommitFileUpload)

Aggregations

RequestCommitFileUpload (im.actor.core.api.rpc.RequestCommitFileUpload)1 ResponseCommitFileUpload (im.actor.core.api.rpc.ResponseCommitFileUpload)1 FileReference (im.actor.core.entity.FileReference)1 RpcException (im.actor.core.network.RpcException)1 FileSystemReference (im.actor.runtime.files.FileSystemReference)1