I need to cancel an in-progress download that was initiated with
fileTransferUtility = new TransferUtility(/*...*/);
var uploadRequest = new TransferUtilityUploadRequest() /* config parameters... */
fileTransferUtility.BeginUpload(uploadRequest, new AsyncCallback(uploadComplete), file);
I have searched SO and documentation, but I can't find a way...
Rationale: the user can pick a file to upload, and may choose a very large file, say 1GB. I need to be able to cancel this.
In the worst case, I could just try to kill the thread entirely, or shut down the upload in an unclean way, but how???
Thanks!
I received an official answer from Amazon on this. Here is their reply:
var fileTransferUtility = new TransferUtility(/* */);
var uploadRequest = new TransferUtilityUploadRequest();
Thread thread = new Thread(() => fileTransferUtility.Upload(uploadRequest));
Thread.Sleep(5000); // If not done in 5 seconds abort
if(thread.IsAlive)
thread.Abort();
Instead of using BeginUpload
/EndUpload
calls, you need to use a Upload
call wrapped in a Thread, and heep the reference to this thread.
If the user needs to cancel, call Abort()
on the thread, which will cancel the upload. Of course, you need to clean partially uploaded files (they bill for them!).
As I suspected: very simple and intuitive, but not so easy to find :)
Try something like :
s3Client.AbortMultipartUpload(new AbortMultipartUploadRequest()
.WithBucketName(bucketName)
.WithKey(key)
.WithUploadId(Response.UploadId));
}
see http://docs.aws.amazon.com/sdkfornet/latest/apidocs/html/M_Amazon_S3_AmazonS3_AbortMultipartUpload.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With