0

I've just read through the documentation of sails-skipper. Looks like a good way of handling multipart file uploads.

However, what if I want to stream an upload of something that isn't a multipart payload? -- in my current case its a simple "text/csv" upload.

I've tried simply using request.pipe ... but this doesn't seem to work.

shaunc
  • 5,317
  • 4
  • 43
  • 58

1 Answers1

0

And the answer is ... skipper isn't going to help here. Rather, (just as in a generic express app) use middleware before skipper which sets req._body = true to fool upstream bodyParser (which is skipper by default for sails).

In my case, in config/http.js:

var typeIs = require('type-is');

module.exports.http = {

  middleware: {

    order: [
      ...
      'dontParseCSV',
      ...
      'bodyParser',
      ...
    ],
    dontParseCSV: function (req, res, next) {
      if(typeIs(req, 'csv')) {
        // fool body parser into thinking already parsed
        // so we can stream csv
        req._body = true;
      }
      next();
    },
  ...
  }
};

The router comes after bodyParser, so it might be a bit inconvenient to do this for just a particular route (at least if you want the router to recognize the route and not just hack in a regexp :)). In my case, all my other routes accept only json, so it isn't a problem.

shaunc
  • 5,317
  • 4
  • 43
  • 58