I'm having difficulty understanding where exactly I should implement wrapAsync/bindEnvironment in the code I'm working on. I am making a call to a url with http/knox and uploading it to my S3 bucket which works, but when I try to call the function in the callback, I get hit with a Meteor code must always run within a Fiber
.
I tried to wrap the callback in bindEnvironment and attempted to use wrapAsync, but must have not understood exactly how this works. Any guidance will be greatly appreciated!
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);
}
});
});
Try this:
S3.knox.putStream(res, `/${imageName}`, headers, Meteor.bindEnvironment(function(err, res) {
//rest of the code
}));