aws-sdk-js: Error : s3.upload.promise() is not a funciton

I’m trying to call the setPromisesAWS.config.setPromisesDependency config function but my config object doesn’t seem to have the setPromisesDependency property. Am I missing something?

AWS.config.setPromisesDependency(bluebird)
// Error : AWS.config.setPromisesDependency is not a function

I have version 2.2.48 installed via bower. Any help would be appreciated.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 21 (6 by maintainers)

Most upvoted comments

Hi @dhatawesomedude

Promises are currently only supported on operations that return a Request object. Since s3.upload is a custom function that returns an instance of ManagedUpload rather than Request, promises are not currently supported for that operation. However, this is a feature request that we are looking into.

As a current workaround, if you know your file’s size, you can use the putObject operation for file sizes <= 5MB, or use the multipart upload operations for file sizes greater than 5MB. The SDK does support promises on all of these operations. You could also create the promise:

var s3UploadPromise = new Promise(function(resolve, reject) {
    s3.upload(params, function(err, data) {
        if (err) {
            reject(err);
        } else {
            resolve(data);
        }
    });
});

I hope that helps!

One last response and then I’ll leave it for you to discuss in https://github.com/aws/aws-sdk-js/issues/1650 as suggested by @jeskew

@niftylettuce I am using code similar to you and am not getting an error:

var AWS = require('aws-sdk/dist/aws-sdk-react-native');
AWS.config.update({
  accessKeyId: myKeyId,
  secretAccessKey: mySecretKey,
  region: myRegion
})

var s3 = new AWS.S3()   
var params = {
  Bucket: "mybucket",
  Key: myKeyPrefix,
  Body: myBody,
  ContentType: 'image/png',
  ContentEncoding: 'base64',
  ACL: 'public-read'  
}
let putObjectPromise = await s3.upload(params).promise()
let location = putObjectPromise.Location

Good luck.

Hi @dhatawesomedude

Thanks for your question. Promises are not supported in the SDK prior to version 2.3.0. If you update to 2.3.0 or later, the setPromisesDependency property will be on AWS.config.

As an update, I believe promises are now supported on ManagedUploads so upload can be used instead of putObject if so desired: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3/ManagedUpload.html#promise-property

Yes I know that, I’m saying that there’s somewhere in the AWS SDK where there is a promise that is not wrapped with a try catch. In my code I wrapped it with a try catch and STILL got an unhandled promise rejection. I’m on latest Node, which is 6.6.x.

Another way to do this in the meanwhile is to use es6-promisify at https://www.npmjs.com/package/es6-promisify. Here’s an example:

const params = { ... }
await promisify(s3.upload, s3)(params);

… or if you’re not using async/await …

const params = { ... }
promisify(s3.upload, s3)(params).then(fn).catch(fn);