Search code examples
meteorstreamfilesystemscollectionfs

Meteor CollectionFS - How can I modify my text file?


I have successfully uploaded a text file into a FS collection store. Now I want to modify the content of that text file or extract some information.

I can get the file object with:

var fileObj = myFSCollection.findOne({});

From what I have read, this is just a pointer to the file and not the file itself. How do I grab the text inside the text file so that I can modify it?


Solution

  • You can get the file itself with fileObj.url(). You cannot, however, update the file that CollectionFS has stored for you. You have to remove the original and insert a new one.

    To download the file:

    HTTP.get(fileObj.url(),function(err,result){
      if ( !err ){
        var content = result.content;
      }
    });