Alk
Alk

Reputation: 5557

Get AWS S3 Upload URL - NodeJs AWS-SDK

I'm pretty sure I'm missing something very obvious here, but:

I'm uploading a file to an s3 bucket using aws-sdk as follows:

const awsURL = await s3.upload(params, (err, data) => {
    if (err) {
        console.log(err);
        return null;
    }
    console.log(`File uploaded successfully. ${data.Location}`);
    return data.Location;
});
return awsURL;

I'm able to log the upload url successfully, however the awsURL returned is an array, not the data.Location value - shouldn't the data.Location be returned from the callback?

Upvotes: 1

Views: 838

Answers (1)

hoangdv
hoangdv

Reputation: 16147

Convert s3.upload to return a promise:

const data = await s3.upload(params).promise(); // this line
console.log(`File uploaded successfully. ${data.Location}`);
return data.Location;

Upvotes: 2

Related Questions