I'm currently uploading files to an S3 bucket using putObject
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 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. 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. How do I retrieve a response with an UploadID
before the 'send'
callback?
Thanks for any help!
-Michael
The S3 PUTObject API is not a multi-part request. The abortMultipartUpload
or completeMultipartUpload
is required or can be used when you initiate the multi-part request using createMultipartUpload
. The response of createMultipartUpload
API returns the uploadId
value.
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.
Multi-part upload steps:-
1) Multi-part upload initiation - API createMultipartUpload
2) Parts upload - API are upload
or uploadPart
3) Multi-part upload completion (or Abort) - API abortMultipartUpload
or completeMultipartUpload
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.