Skip to content
Advertisement

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?

Advertisement

Answer

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;
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement