I’m a bit confused why this code is not working. Shouldn’t this work? When we put a return outside of the cloudinary function callback it works, when within the callback of cloudinary it isn’t. But shouldn’t it? I understand that cloudinary is waiting for the callback to be run, which IS happening. But when we do a return to exit the method, it’s actually returning undefined.
On the server:
imageUpload: function (imageFile) {
// this works
// return 'bla';
cloudinary.v2.uploader.upload('https://www.houseme.space/img/hero_image.jpg',{
crop: 'limit', width: 400, height: 400, tags: ['profileImages'], folder: 'profileImages',
}, (err, res) => {
if(err) {
console.log(err);
} else {
// this does not
return 'bla';
}
});
},
On the Client:
Meteor.call('imageUpload', file, (err, res) => {
if(err) {
console.log(`error is ${err}`);
return;
} else {
console.log(`result is ${res}`);
}
});
If the upload encounters an error, I think it will throw an error on its own. Maybe. You may wanna also try wrapping the upload call in a try/catch to check.
If I had had my cup of coffee, I would’ve figured this out the first time.