Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
290 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 Answer

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);
            });
        });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...