流星光纤问题与回调在诺克斯

Meteor Fiber issue with callback in knox

本文关键字:回调 光纤 问题 流星      更新时间:2023-09-26

我很难理解我应该在哪里实现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);
    }
  });
});

试试这个:

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