Add a custom property to GridFS Meteor FS file during upload

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.

Answers:

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.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.