我很难理解我应该在我正在编写的代码中实现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);
}
});
});
答案 0 :(得分:1)
试试这个:
S3.knox.putStream(res, `/${imageName}`, headers, Meteor.bindEnvironment(function(err, res) {
//rest of the code
}));