我有代碼在裁剪圖像之前將其保存到集合,但代碼異步執行。在圖像被裁剪之前插入到集合執行。流星執行功能同步
Meteor.methods({
'createWorkout': function(workoutFormContent, fileObj) {
// crop image to width:height = 3:2 aspect ratio
var workoutImage = gm(fileObj.path);
workoutImage.size(function(error, size) {
if (error) console.log(error);
height = size.height;
width = size.height * 1.5;
workoutImage
.gravity("Center")
.crop(width, height)
.write(fileObj.path, function(error) {
if (error) console.log(error)
});
});
// add image to form content and insert to collection
workoutFormContent.workoutImage = fileObj;
Workouts.insert(workoutFormContent, function(error) {
if (error) {
console.log(error);
}
});
},
});
如何能夠同步運行此代碼以便能夠插入已裁剪的圖像?
你需要在回調中運行它。 – SLaks