vsivsi / meteor-file-collection

Extends Meteor Collections to handle file data using MongoDB gridFS.
http://atmospherejs.com/vsivsi/file-collection
Other
159 stars 37 forks source link

copying files #146

Closed dpatte closed 7 years ago

dpatte commented 7 years ago

Any hints on the easiest way of copying a file that exists in my meteor file collection? I want to make a copy, then modify an ownerId field that I have defined in the metadata, so that each user then has their own copy from that point on.

vsivsi commented 7 years ago

GridFS, the MongoDB file storage spec that file-collection is built on, doesn't offer any block deduplication / reference counting functionality. Duplicate files require duplicate storage at the gridFS level. If you are fine with that, then the easiest way to copy a file is to use fc.findOneStream() and fc.upsertStream() and to pipe the readable stream into the writable one using the normal node.js mechanism.

If you do not wish to have physically duplicated gridFS files, then it gets more complicated. You would then need to create a new logical collection of some kind that is backed by the actual file collection, but implements file level deduplication (based on md5) and reference counting policies in the gridFS file metadata. It's doable, but you'd need to do the work, as gridFS and file-collection do not implement these features.

Hope that helps.

dpatte commented 7 years ago

Thank you very much. Good advice.