Search code examples
javascriptjquerymeteorgraphicsmagick

Showing multiple stores with collectionFS


Do you know how to show a specific store? I have two stores.

I am using the package cfs-ejson to store the image in a field in my collection via a imageObj field

var imageStore = new FS.Store.S3("mains", {
  accessKeyId: "XXXXXXX", 
  secretAccessKey: "XXXXXXX", 
  bucket: "XXXXXXX",
  transformWrite: function(fileObj, readStream, writeStream) {
          gm(readStream, fileObj.name()).resize('500', '500').stream().pipe(writeStream);
  }

});

var thumbStore = new FS.Store.S3("thumbs", {
  accessKeyId: "XXXXXXX", 
  secretAccessKey: "XXXXXXX", 
  bucket: "XXXXXXX",
  transformWrite: function(fileObj, readStream, writeStream) {
          gm(readStream, fileObj.name()).resize('100', '100').stream().pipe(writeStream);
  }
});


Images = new FS.Collection("images", {
  stores: [imageStore, thumbStore]
});

I have tried to access the main version via {{ photo.url store="mains" }} however it just get the thumbnail version.

It seems to be just saving one image in the s3 bucket, maybe I need to set the thumbnail to have a different filename?


Solution

  • You can add (undocumented right now) folder parameter to storage options.

    new FS.Store.S3("thumbs", {
      bucket: "XXXXXXX",
      folder: "thumbs"
    }
    

    This will be appended to path before file key.

    Otherwise you get a race condition on file save, thats why you get thumbnail version even if you specify "mains".