I’ve been using cfs:grids for some time, but am having trouble resizing images placed in multiple stores. Until now I used a single store. I have added stores for the original image, a web optimized size, and a thumbnail size. The stores seem to be working. Images are being put into them and I can retrieve them by store. The problem is they are not being resized. I’ve followed the examples I’ve found online, but no joy. GM is installed on the development machine and I’ve been able to resize files from the command line using the convert command. Here’s the meteor code I’ve got now. Any help is appreciated.
var imageFileStore = new FS.Store.GridFS(‘imagefiles’, {
maxTries: 1
});
var imageThumbFileStore = new FS.Store.GridFS(‘imagethumbfiles’, {
maxTries: 1,
transformWrite: createThumbFile
});
var imageWebFileStore = new FS.Store.GridFS(‘imagewebfiles’, {
maxTries: 1,
transformWrite: createWebFile
});
var createThumbFile = function(fileObj, readStream, writeStream) {
// Transform the image into a 256x256px thumbnail
gm(readStream, fileObj.name()).resize(‘256’, ‘256’).stream().pipe(writeStream);
};
var createWebFile = function(fileObj, readStream, writeStream) {
// Transform the image into a 1920x1200px image
gm(readStream, fileObj.name()).resize(‘1920’, ‘1200’).stream().pipe(writeStream);
};
Imagefiles = new FS.Collection(‘imagefiles’, {
stores: [
imageFileStore,
imageThumbFileStore,
imageWebFileStore
],
});
Imagefiles.allow({
insert:function(){
return true;
},
update:function(){
return true;
},
remove:function(){
return true;
},
download:function(){
return true;
}
});
Meteor.methods({
addImagefile: function(theFile) {
var user = Meteor.user();
if(!user) {
throw new Meteor.Error(401, “You need to login to post new items”);
}
var imagefileId = Imagefiles.insert(theFile,function(err,fileObj){
if(!err){
//do something if there is no error.
}
});
return imagefileId;
},
removeImagefile: function(currentPostId){
return Imagefiles.remove({imageId: currentPostId});
}
});