meteor Dropzone (with iron:router)


If we want something a bit more polished, with an integrated Dropzone UI and a REST endpoint, we're going to need to start adding custom REST routes and packages with UI helpers.

Lets begin by importing Iron Router and Dropzone.

 meteor add iron:router
 meteor add awatson1978:dropzone

And configure the uploads url route that's specified in the dropzone helper. () {
    this.route('uploads', {
      where: 'server',
      action: function () {
        var fs = Npm.require('fs');
        var path = Npm.require('path');
        var self = this;

        ROOT_APP_PATH = fs.realpathSync('.');

        // dropzone.js stores the uploaded file in the /tmp directory, which we access
        fs.readFile(self.request.files.file.path, function (err, data) {

          // and then write the file to the uploads directory
          fs.writeFile(ROOT_APP_PATH + "/assets/app/uploads/", data, 'binary', function (error, result) {
              console.log('Success! ', result);

Cool! We have a file uploader with snazzy UI and a programmable REST endpoint. Unfortunately, this doesn't scale particularly well.