Is there any other better package for file storage than CollectionFS?

I am getting frustrated that there’s no other way to handle filestorage in meteor that doesn’t involve cloud services.

I’m having trouble with this package returning a callback when the upload has finished or has been stored in the database.

According to https://github.com/CollectionFS/Meteor-CollectionFS/issues/323

one can use

filesCollection.on('stored', function (fileObj, storeName) {
  // do something
});

but it errors out Error: Can't wait without a fiber

I have no way telling the client their upload has finished and showing them the uploaded image.

Now using

filesCollection.on('uploaded', function (fileObj) {
  // do something
});

works but it just says that it was uploaded, not stored with a url so I can show back to the client.

Here’s my method:

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);
        // return fileObj.url();
        console.log('not uploaded yet');
        Images.on('uploaded', function (fileObj, storeName) {
          // do something
          console.log('uploaded');
          done(null, 'Finished');
        });
      });
    });

    console.log('storing');
    return response;
  }
});

PS, I’m calling this method from outside of Meteor.

edit

Just realized, calling multiple times Images.on will duplicate the callbacks I get from that… how do I handle such thing >.<

edit 2

For some reason it’s working now but now I got the other problem

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?

I guess there’s no other way :frowning:

i don’t know that this will help, but i ended up writing my own so i use github for storage. as a result, the methods just become a post or get or whatever, but i always get a nice response to return. Seems to be working ok for me.

fyi - i have not yet gone down this route, but in an ideal world for large files could use github lfs

2 Likes