I need to cancel an in-progress download that was initiated with
fileTransferUtility = new TransferUtility(/*...*/);
var uploadRequest = new TransferUtility
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
Wrapping the Upload into a thread works, but, at least to me, it takes quite a long time, if the file is big to Abort the thread. Anyone sees this too?
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 :)