'Javascript AWS S3.upload gives a promise?
The AWS instructions on S3 uploading (https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3/ManagedUpload.html) would suggest that the following should work.
var managed = s3.upload(params, function(err, data) {
if (err) {
throw err;
}
console.log(`File uploaded successfully. ${data.Location}`);
});
p = managed.promise();
console.log(p);
s3.upload returns a ManagedUpload object, and this seems to be working. Supposedly the object has a promise() method that returns a promise that could be used with the .then programming style. However, when I actually try I'm getting
Uncaught TypeError TypeError: managed.promise is not a function
Is this documentation out of date? Is there a better one somewhere?
Solution 1:[1]
From the docs in upload()
just enter the parameters, then()
method should be called on the promise object to handle a result (resolve) or an error (reject).
var upload = s3.upload({Bucket: 'bucket', Key: 'key', Body: stream});
var promise = upload.promise();
promise.then(function(data) { ... }, function(err) { ... });
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |