Search code examples
sails.jsskipper

Sails skipper fails silently


Using the code copied and pasted from the docs, the upload is not raising any errors (as is evidenced by the fact that if there was an error, it would return an HTTP status of 500 along with the error message).

req.file('avatar').upload(function (err, uploadedFiles) {
    if (err) return res.send(500, err);
    return res.json({
        message: uploadedFiles.length + ' file(s) uploaded successfully!',
        files: uploadedFiles
    });
});

However, uploadedFiles ends up with a length of 0.

I'm using the local disk adapter.

Any guesses on what could be going wrong?


Solution

  • From the skipper github. It doesn't class an empty content length as an error. It simply skips all the hard body parsing work.

    if (
      // If we have a content-length header...
      !_.isUndefined(req.headers['content-length']) &&
      // And the content length is declared to be zero...
      (req.headers['content-length'] === 0 || req.headers['content-length'] === '0')) {
      // Then we set the body to any empty object
      // and skip all this body-parsing mishegoss.
      req.body = {};
      return next();
    }