S3 Multipart Upload: how can I cancel it?

I need to cancel the bootstrap started with

fileTransferUtility = new TransferUtility(/*...*/); var uploadRequest = new TransferUtilityUploadRequest() /* config parameters... */ fileTransferUtility.BeginUpload(uploadRequest, new AsyncCallback(uploadComplete), file); 

I searched for SO and documentation, but I cannot find a way ...

Rationale: The user can select a file to download and can select a very large file, say 1 GB. I need to undo this.

In the worst case, I could just try to completely destroy the stream or disable the download in an unclean way, but how ???

Thanks!

+6
source share
3 answers

I received an official response from Amazon on this. Here is their answer:

 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 you need to use the Upload call wrapped in the stream and start the link to this stream.

If the user needs to cancel, call Abort() on the thread, which will cancel the download. Of course, you need to clear partially downloaded files (they are credited to them!).

As I suspected: very simple and intuitive, but not so easy to find :)

+5
source

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

+1
source

Wrapping a download into a stream works, but at least for me it takes quite a while if the file is large to interrupt the stream. Does anyone see this too?

0
source

Source: https://habr.com/ru/post/944721/


All Articles