简体   繁体   中英

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?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM