【问题标题】:Meteor Fiber issue with callback in knox诺克斯回调的 Meteor Fiber 问题
【发布时间】:2017-02-15 07:57:02
【问题描述】:

我很难理解在我正在处理的代码中应该在哪里实现 wrapAsync/bindEnvironment。我正在使用 http/knox 调用一个 url 并将其上传到我的 S3 存储桶,它可以工作,但是当我尝试在回调中调用该函数时,我被Meteor code must always run within a Fiber 击中。

我尝试将回调包装在 bindEnvironment 中并尝试使用 wrapAsync,但一定没有完全理解它是如何工作的。任何指导将不胜感激!

http.get(imageUrl, function(res) {
  let headers = {
    'Content-Length': res.headers['content-length']
    , 'Content-Type': res.headers['content-type']
  };
  S3.knox.putStream(res, `/${imageName}`, headers, function(err, res) {
    if (err) {
      log.error(`(imageUpload): Error uploading image with knox: ${err}`);
    } else {
      let amazonImagePath = `https://s3.amazonaws.com/${bucketName}/${imageName}`;
      // TODO Figure out why fiber issue is happening with expenseInsert in callback
      expenseInsert(expenseObj, amazonImagePath);
    }
  });
});

【问题讨论】:

    标签: javascript meteor knox-amazon-s3-client fiber


    【解决方案1】:

    试试这个:

    S3.knox.putStream(res, `/${imageName}`, headers, Meteor.bindEnvironment(function(err, res) {
        //rest of the code    
    }));
    

    【讨论】:

      猜你喜欢
      • 2015-08-16
      • 1970-01-01
      • 1970-01-01
      • 2021-04-16
      • 2012-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多