admin管理员组文章数量:1391934
Using Node AWS SDK which supports callbacks and promises.. /
Using q as promise library..
AWS.config.setPromisesDependency(q);
const headObjProm = this.s3Client.headObject(headParams).promise();
headObjProm
.then(ret => {
//ret is promise..
})
console logging ret
shows..
(resolve, reject) {
self.on('plete', function(resp) {
if (resp.error) {
reject(resp.error);
} else {
resolve(resp.data);
}
});
I was under impression ret
would be data or error message?
The documentation on AWS is all done in callback style.
How to use this with promises?
Using Node AWS SDK which supports callbacks and promises.. https://aws.amazon./blogs/developer/support-for-promises-in-the-sdk/
Using q as promise library..
AWS.config.setPromisesDependency(q);
const headObjProm = this.s3Client.headObject(headParams).promise();
headObjProm
.then(ret => {
//ret is promise..
})
console logging ret
shows..
(resolve, reject) {
self.on('plete', function(resp) {
if (resp.error) {
reject(resp.error);
} else {
resolve(resp.data);
}
});
I was under impression ret
would be data or error message?
The documentation on AWS is all done in callback style.
How to use this with promises?
2 Answers
Reset to default 3When you're initializing the Q
package as the Promise to use, you need to specify the Promise
property from Q
.
AWS.config.setPromisesDependency(require('Q').Promise);
Since const headObjProm = this.s3Client.headObject(headParams).promise();
is asynchronous, how about say you have this in an async function and use await like so:
`const resolveHeadObject = async()=> await s3Client.headObject(headParams).promise()`
I use the await/async
syntax and it works for me.
Don't forget to add .Promise
to your Q
require as well, if that's necessary.
本文标签: javascriptHow to use promises with AWS headObjectStack Overflow
版权声明:本文标题:javascript - How to use promises with AWS headObject? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744700581a2620540.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论