How to upload multipart files in aws s3 bucket using javascript sdk in browser

给你一囗甜甜゛ 提交于 2020-01-06 02:54:09

问题


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.



来源:https://stackoverflow.com/questions/30977735/how-to-upload-multipart-files-in-aws-s3-bucket-using-javascript-sdk-in-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!