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

Viewed 122

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

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