S3多部分上传:我怎样才能取消呢? [英] S3 Multipart Upload: how can I cancel one?

查看:209
本文介绍了S3多部分上传:我怎样才能取消呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要取消正在进行的下载软件,与启动

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

我已搜查SO和文件,但我不能找到一种方法...

I have searched SO and documentation, but I can't find a way...

理由:用户可以选择要上传的文件,并且可以选择一个非常大的文件,说1GB。我需要能够取消此

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???

谢谢!

推荐答案

我收到的来自Amazon官方的回答的这一点。下面是他们的回答:

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();

而不是使用 BeginUpload的 / EndUpload的呼叫,您需要使用上传呼叫包裹在一个线程,及协参照此主题。

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

这篇关于S3多部分上传:我怎样才能取消呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆