Skip to content
This repository has been archived by the owner on Mar 14, 2019. It is now read-only.

How to: Add custom metadata to a file before inserting

Philipp edited this page Mar 1, 2015 · 1 revision

You can set any additional properties on your file object before inserting. To avoid conflicts with built-in properties and method names, you may want to group them in one object property, like metadata. For example, with a file input:

Template.myForm.events({
  'change .myFileInput': function(event, template) {
    FS.Utility.eachFile(event, function(file) {
      var newFile = new FS.File(file);
      newFile.metadata = {foo: "bar"};
      Images.insert(newFile, function (err, fileObj) {
        //If !err, we have inserted new doc with ID fileObj._id, and
        //kicked off the data upload using HTTP
      });
    });
  }
});