cmather/meteor-file

Callback on save?

Opened this issue · 1 comments

Hi! Any chance we could get a callback on the save function. I saw you wrote this using the fibers/future npm library.

_.extend(MeteorFile.prototype, {
  save: function (dirPath, options) {
    // should do dirPath checking here (see the next video or two in the series)
    var filepath = path.join(dirPath, this.name);
    var buffer = new Buffer(this.data);
    var future = new Future;

    // the future has a method named resolver that acts like a callback function that works with fibers
    fs.writeFile(filepath, buffer, options, future.resolver());

    // block the current fiber only (not the rest of the event loop)
    return future.wait();
  }
});

But I don't understand how to use it, lol.

Hey @Lepozepo, I'll come back to this when I end up integrated the file uploader into my own app. We could add a callback but Meteor code tends to be written in a synchronous style. In this case, you would just call the save() method on your file on the server (like from a Meteor method). The save method actually needs to be updated to use the async version of the node module writeFile. Check out this thread if you want to take a stab at it: https://www.eventedmind.com/posts/meteor-file-uploader-part-2-server-side-save