With dburles:collection-helpers package you can add collection helpers on any Mongo.collection. But I can't do that on FS.Collection. I get TypeError: Object [object Object] has no method 'helpers'. Transform function doesn't work either.
var createUploader = function(fileObj, readStream, writeStream) {
fileObj.uploadedBy = Meteor.users.find({_id: fileObj.uploader});
readStream.pipe(writeStream);
};
Photos = new FS.Collection("photos", {
stores: [
new FS.Store.GridFS("photos", {transformWrite: createUploader})
],
filter: {
allow: {
contentTypes: ['image/*']
}
}
});
Can't do this? Notice when a photo is inserted from the client FS.File
gets userId
, hence fileObj.uploadedBy = Meteor.users.find({_id: fileObj.uploader});
Ok I know this is not the not-so-easy solution I was looking for. Since I am using publish-composite package. I can just publish users' data(only profile field) with photos. And on the client I can do template helper like this:
and
then
matb33-collection-helpers package works by applying a transform function to a collection. CollectionFS already has its own transform function applied, therefore you cannot overwrite that with ones from the collection helpers package.
As suggested at the issue tracker
You could define custom functions on the prototype. The prototype will have access to other properties of the doc through
this
so you would basically have the same functionality with collection helpers.Another option would be to store the file related information on the individual file object during the insert as metadata such as:
Your code can also be rewritten to implement a
beforeWrite
filter instead of a transformWrite as inFinally, you can opt to storing the ID of the user and publishing a reactive join
And for the publication, you can use
reywood:publish-composite
Of course on the client, you need to subscribe to the
photosWithUsers
publication.Now to access that information in the client, since you cannot apply a transform or a helper on the collectionFS documents, you can create a global template helper:
Now you can use that helper in your templates: