I have implemented a file upload and download capability in my Android app using the example approaches posted on GitHub. However, I need a way to interrupt the process to support the notion of 'cancel' by the user. There doesn't seem to be a way to do this? Once I get this far:
FileMetadata metadata = dbxClient.files().uploadBuilder(uploadPath + "/" + localFile.getName())
.withMode(WriteMode.OVERWRITE)
.withClientModified(new Date(localFile.lastModified()))
.uploadAndFinish(in, progressListener);
This blocks internally to the API until the upload is complete. I realize I can use the 'limit' setting in a loop like this:
while ((size - uploaded) > CHUNKED_UPLOAD_CHUNK_SIZE) {
dbxClient.files()
.uploadSessionAppendV2(cursor)
.uploadAndFinish(in, CHUNKED_UPLOAD_CHUNK_SIZE, progressListener);
uploaded += CHUNKED_UPLOAD_CHUNK_SIZE;
cursor = new UploadSessionCursor(sessionId, uploaded);
}And then check for an interrupted condition prior to initializing 'cursor' again, is this the only way? It means a delay to the user depending on how big "CHUNKED_UPLOAD_CHUNK_SIZE" is, and I'd rather not have to play games optimizing this value on the relatively low chance that the user cancels. I'd rather be able to interrupt the process whenever it needs to be interrupted.