Ad
AWS S3 Upload Not Working After Converting From Callback To Async-Await Format Using Promisify
I'm using upload method from aws-sdk to upload files to S3 bucket from React app in browser.
The original callback based upload method is as bellow:
var params = {Bucket: 'bucket', Key: 'key', Body: stream};
s3.upload(params, function(err, data) {
console.log(err, data);
});
I wrapped it with promisify to work it like Async-await as bellow:
const AWS = require('aws-sdk');
const { promisify } = require('es6-promisify');
... <in my React component> ...
async uploadFile() {
try {
var params = {
Bucket: <BucketName>,
Key: <KeyName>,
Body: <File Stream>
};
const res = await uploadToS3Async(params);
console.log(res);
} catch (error) {
console.log(error);
}
}
Now when I'm calling uploadFile
function on some event fired it produces following error:
TypeError: service.getSignatureVersion is not a function
at ManagedUpload.bindServiceObject
at ManagedUpload.configure
at new ManagedUpload
at upload
at new Promise (<anonymous>)
Ad
Answer
You don't need to use es6-promisify
You can do:
try {
const params = {Bucket: 'bucket', Key: 'key', Body: stream};
const data = await s3.upload(params).promise();
console.log(data);
}
catch (err) {
console.log(err);
}
https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/using-promises.html
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad