Meteor-Community-Packages/Meteor-CollectionFS

Images.on('stored') in a method keeps going and duplicating each time.

johhansantana opened this issue · 0 comments

Meteor.methods({
  insertImage: (fileUrl) => {

    const response = Async.runSync((done) => {
      Images.insert(fileUrl.url, function (err, fileObj) {
        if (err) throw new Meteor.Error('500', err, err);
        Images.on("stored", function(fileObj, storeName){
          console.log('stored');
          done(null, 'Finished');
        });
        Images.on('uploaded', function (fileObj, storeName) {
          console.log('uploaded');
        });
      });
    });
    return response;
  }
});

Each time I call this method the console.logs will get duplicated. Is there another better way to know when the image finished uploading so I can return a callback? If not, will this impact my app in any way?