2016-10-06 83 views
0

我很難理解我應該在我正在處理的代碼中實現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); 
    } 
    }); 
}); 

回答

1

試試這個:

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