Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

amazon web services - Does AWS SDK for Javascript work in a web worker (for performing Multi-part upload)?

I was trying to use AWS SDK for JS to perform a multipart upload in a web worker. When i initiate a createMultipartUpload, I am able to see the uploadID in api call for incomplete multipart upload. But the createMultipartUpload is not returning the upload ID. Can we use the AWS SDK for JS on the web worker? and if so am I doing anything wrong here?

Code:

  a=s3.createMultipartUpload(params, function (err, data) {
        //Execution doesn't reach here
        console.log(data);
        if (err) {
            console.log(err, err.stack); // an error occurred
        } else {
            uploadId = data.UploadId
        }
    });
question from:https://stackoverflow.com/questions/65880612/does-aws-sdk-for-javascript-work-in-a-web-worker-for-performing-multi-part-uplo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you can encapsulate that into a promise :

        uploadId = await new Promise((resolve, reject) => {
            s3Client.createMultipartUpload(initParams, function(err, res) {
                if (err) {
                    s3Client.abortMultipartUpload();
                    reject();
                }
                uploadId = res.UploadId;
                resolve(uploadId);
            });
        });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...