Change http request limit in Sailsjs

2.2k Views Asked by At


I'm having a 413 Request Entity Too Large in a request, because I send several URI Image base64 encoded, and that's a lot of characters.

Anyway, I can't find a way to extend this limit in SailJS. Apparently Sails use Skipper for the bodyParser, but I can't find anything in the skipper doc.

I guess it's in the http config file...

If someone can tell me how :) Thanks !

2

There are 2 best solutions below

2
On

AFAIK it's configurable when you create controller that handle that uploads, like:

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

But they said it's currently still experimental. Look at this Skipper's Docs.

0
On

This solution worked for us https://github.com/balderdashy/sails/issues/2653

Sails is using skipper for body parser. You can configure or change default skipper configuration by creating a middleware in config/http.js:

configuredSkipperBodyParser: function () {
        var opts = {limit:'50mb'};
        var fn;

        // Default to built-in bodyParser:
        fn = require('skipper');
        return fn(opts);
    }

Then set it instead of default body parser:

order: [
            'startRequestTimer',
            'cookieParser',
            'session',
            'myRequestLogger',
            'configuredSkipperBodyParser',
            'handleBodyParserError',
            'compress',
            'methodOverride',
            'poweredBy',
            '$custom',
            'router',
            'www',
            'favicon',
            '404',
            '500'
        ]

Hope this is helpful.