S3 Multipart Upload: how can I cancel one?

前端 未结 3 852
无人及你
无人及你 2021-01-05 14:28

I need to cancel an in-progress download that was initiated with

fileTransferUtility = new TransferUtility(/*...*/);
var uploadRequest = new TransferUtility         


        
相关标签:
3条回答
  • 2021-01-05 14:58

    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

    0 讨论(0)
  • 2021-01-05 15:00

    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?

    0 讨论(0)
  • 2021-01-05 15:07

    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 :)

    0 讨论(0)
提交回复
热议问题