We’re adding an uploaded image to Cloudinary, but it takes a few seconds to happen. I have never used promises before and am curious if someone can help me understand how to refactor this code to work with promises, or if promises are even what I need to help stabilize this section of the code.
It’s currently uploading the file, creating an “Images” record for the file, then attaching the _id of the image to a field in the communities table.
Cloudinary.upload(files, {}, (error, response) => {
if (error) {
Bert.alert( error.reason, 'danger' );
} else {
Meteor.call( 'newImage', response, ( error, response) => {
if (error) {
Bert.alert( error.reason, 'danger' );
} else {
let community = component.buildCommunity(response);
Meteor.call( 'updateCommunity', community, ( error, response ) => {
if ( error ) {
Bert.alert( error.reason, 'danger' );
} else {
Bert.alert( 'Community updated', 'success' );
FlowRouter.go('/communities');
}
});
}
});
}
});
I have been looking at http://deanius-promise.meteor.com/#call-promise and I think it might help to use promises here, but just don’t have any experience with them. Any suggestions or direction would be greatly appreciated.