如何在AWS HeadObject中使用Promise? [英] How to use promises with AWS headObject?

查看:174
本文介绍了如何在AWS HeadObject中使用Promise?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用支持回调和承诺的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆