简体   繁体   English

AWS S3 SDK:中止正在进行的putObject上传

[英]AWS S3 SDK: Abort a putObject upload in progress

I'm currently uploading files to an S3 bucket using putObject 我目前正在使用putObject将文件上传到S3存储桶

params = {
    Key: videoKey,
    ContentType: file.type,
    Body: file,
    ACL: "public-read"
};

req = s3.putObject(params).on('httpUploadProgress', function(evt) {
    // calculate percentage complete
    var percentComplete = Math.round(evt.loaded / evt.total * 100);

    $cancelBtn.on("click", function(evt) {
      req.abort.bind(req); // doesn't work; returns an error
    });
}).send(function(err, data) {
    // code to handle what happens after upload completes
});

I've read in multiple locations to use req.abort() or req.abort.bind(req) , but this seems to be returning the following error: 我已经在多个位置阅读过以使用req.abort()req.abort.bind(req) ,但这似乎正在返回以下错误:

'req.abort is not a function. (In 're.abort()', 'req.abort' is undefined)'

It's true 'req' doesn't seem to have an abort() function in its Object, so I'm wondering if this is just tied to an older version of the AWS SDK. 确实'req'似乎在其Object中没有abort()函数,因此我想知道这是否仅与旧版本的AWS开发工具包相关。 If so, what's the proper way to deal with this? 如果是这样,处理此问题的正确方法是什么? I've read some documentation on Amazon's website for a method called abortMultipartUpload but this method requires an UploadId and I can't figure how to retrieve this from my putObject function. 我已经在亚马逊网站上阅读了一些文档,以了解一种名为abortMultipartUpload的方法,但是该方法需要一个UploadId ,我无法弄清楚如何从我的putObject函数中检索该方法。 How do I retrieve a response with an UploadID before the 'send' callback? 如何在'send'回调之前检索带有UploadID的响应?

Thanks for any help! 谢谢你的帮助!

-Michael -迈克尔

The S3 PUTObject API is not a multi-part request. S3 PUTObject API不是多部分请求。 The abortMultipartUpload or completeMultipartUpload is required or can be used when you initiate the multi-part request using createMultipartUpload . 需要使用abortMultipartUploadcompleteMultipartUpload或在使用createMultipartUpload初始化多部分请求时使用它们。 The response of createMultipartUpload API returns the uploadId value. createMultipartUpload API的响应返回uploadId值。

createMultipartUpload(params = {}, callback) ⇒ AWS.Request Initiates a multipart upload and returns an upload ID.Note: After you initiate multipart upload and upload one or more parts, you must either complete or abort multipart upload in order to stop getting charged for storage of the uploaded parts. createMultipartUpload(params = {},回调)⇒AWS.Request启动分段上传并返回一个上传ID。注意:启动分段上传并上传一个或多个分段后,您必须完成或中止分段上传才能停止获取负责存储上传的零件。

Multi-part upload steps:- 分段上传步骤:-

1) Multi-part upload initiation - API createMultipartUpload 1) createMultipartUpload上传启动-API createMultipartUpload

2) Parts upload - API are upload or uploadPart 2)零件上传-API是upload还是uploadPart

3) Multi-part upload completion (or Abort) - API abortMultipartUpload or completeMultipartUpload 3) abortMultipartUpload上传完成(或中止)-API abortMultipartUploadcompleteMultipartUpload

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM