Ad

Add A Custom Property To GridFS Meteor FS File During Upload

- 1 answer

I'm currently creating a file upload and display feature for a web app.

I need to add a custom property (e.g accountID) so that I can later display only the images belonging to a specific account.

I'm using cfs:standard-packages with gridfs to upload/store my images.

I believe I need to add a beforeWrite function to the FS.Store but am unsure how to go about it.

Ad

Answer

The easiest way to do this is to immediately update the inserted object as follows:

var fileId = MyFiles.insert(file);
MyFiles.update({ _id: fileId },{ $set: { accountId: myAccountId }});

Note that the actual upload of the file object to the store will be asynchronous but you'll get the _id back synchronously and immediately.

Ad
source: stackoverflow.com
Ad