Meteor-files: Is there a way to clone a file and record?

Created on 8 May 2020  路  6Comments  路  Source: veliovgroup/Meteor-Files

As title, with a FileCursor is there something like .clone() to clone the file record and file itself, then return the new FileCursor?

I'm going to invent it but I want to make sure I'm not reinventing the feature. You can't just Collection.insert(FileCursor) just like CollectionFS right?

.write() question

All 6 comments

Hello @urakagi ,

No, there is no such feature as of today. But sounds like a good candidate.
Collection.insert(FileCursor) won't work neither. .insert() method is available only on the Client
Right now you got to read the file using fs on server, then you have next options:

  1. .write() method to create new file out of Buffer;
  2. Write file on FS using fs module, then using .addFile() method create new file using its path;

@dr-dimitru Thank you, can you mention a method to get ReadStream or File object from a FileCursor rather than using .link()?

@urakagi .link() method won't help you; __This got to be done on server__.

Use _storagePath as per Schema:

import fs from 'fs';

const path = FilesCollectionInstance.collection.findOne({_id: '_file_id_'})._storagePath;
FilesCollectionInstance.write(fs.readFileSync(path), {fileOpts});

See .write() method and fs module docs for more details.

Feel free to open new ticket for .copy() or .clone() method

I guess for this code it's path rather than _storagePath? Thank you!

@urakagi I鈥檓 glad this one is solved, feel free to open feature request for .copy()/.clone() method

Please support this project with:

Was this page helpful?
0 / 5 - 0 ratings