How to upload multipart files in aws s3 bucket usi

2019-08-08 10:00发布

问题:

I have tried using the function

var bucket = new AWS.S3({params: {Bucket: 'mybucket'}});
var params = {Key: file.name, ContentType: file.type};
bucket.createMultipartUpload(params, function (err, data) {
    if (err) console.log(err, err.stack); // an error occurred
    else     console.log(data);           // successful response
});

Its getting successful response consists of uploadedid but i cant find the file in the s3 bucket. So is there any other ways for multipart upload files from javascript sdk from browser??. I am using aws cognito for authentication. Thanks in advance.

回答1:

The key you are using is the filename. So the file if uploaded properly should be present at mybucket/file.name.Moreover you can log things on console to see if anything is going wrong.



回答2:

Actually it is a four step process. You have called the first Api and there are three remaining apis to be called.

The order is as follows :

2.http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#uploadPart-property. 3.http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#listParts-property. 4.http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#completeMultipartUpload-property.

For all the above three apis you have to use the same key-name (that you have used in your first api) and upload-id (that you got from the first api's response)

In second api, you have to upload your file along with a 'partnumber' of your choice.

Then from third api call, you can get the 'TagId' generated for your file along with the 'partnumber' you used.

Now using this TagId and partnumber, you have to call the final api.

This completes your file upload.