コレクションに保存する前に画像をトリミングするコードがありますが、コードは非同期で実行されます。コレクションに挿入すると、イメージがトリミングされる前に実行されます。Meteorは関数を同期的に実行します
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