如何在AWS HeadObject中使用Promise? [英] How to use promises with AWS headObject?
问题描述
使用支持回调和承诺的Node AWS SDK. https://aws.amazon.com/blogs/developer/support-for-promises-in-the-sdk/
Using Node AWS SDK which supports callbacks and promises.. https://aws.amazon.com/blogs/developer/support-for-promises-in-the-sdk/
使用q作为Promise库.
AWS.config.setPromisesDependency(q);
Using q as promise library..
AWS.config.setPromisesDependency(q);
const headObjProm = this.s3Client.headObject(headParams).promise();
headObjProm
.then(ret => {
//ret is promise..
})
显示
控制台日志记录ret
.
(resolve, reject) {
self.on('complete', function(resp) {
if (resp.error) {
reject(resp.error);
} else {
resolve(resp.data);
}
});
我受到印象ret
是数据还是错误消息?
AWS上的文档全部以回调样式完成.
如何将其与Promise一起使用?
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?
推荐答案
在将Q
包初始化为要使用的Promise时,需要从Q
指定Promise
属性.
When 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);
这篇关于如何在AWS HeadObject中使用Promise?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!