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;