4

I am trying to post a lot of data to my sails API and I get this 413 error:

Unable to parse HTTP body- error occurred - Error: request entity too large

I have tried a lot of solutions suggested in differents discussions but it never works and seems to be for previous sails version. (it’s always about changing the bodyParser options)

Does anybody know the correct syntax for sails 0.10.5? Thanks a lot!

sheoak
  • 91
  • 1
  • 6
  • 2
    First: there is no sails 0.10.15. Second: the bodyParser in sails is just the express body parser middleware; can you post the actual request you are sending? – Travis Webb Feb 13 '15 at 03:54
  • Sorry it was a typo, it’s 0.10.5. The actual request is big (2M) and it works when it is smaller. I just want to change the default limit. – sheoak Feb 14 '15 at 09:14
  • I am getting same problem. – Nishchit Feb 14 '15 at 09:27

2 Answers2

4

Does anybody know the correct syntax for sails 0.10.5? Thanks a lot!

Take a look at this resolution (sails v.0.11.0, config/http.js):

module.exports.http = {

  middleware: { ... },

  bodyParser: function(){
    var opts = {
      limit:'10mb'
    }
   return require('./../node_modules/sails/node_modules/skipper')(opts);
  }
}
tsv.titan
  • 71
  • 3
3

You might want to add the parameterLimit option too.
Here's what work for me. Using sails.js 0.12
Somehow the bytes library parses the '10mb' string wrongly. Lazy to check out the regular expression, so I just input in a number directly.

Code snippets:

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

 bodyParser: (function () {
     var opts = {limit:10000000, parameterLimit:10000};
     var fn;

     // Default to built-in bodyParser:
     fn = require('skipper');
     return fn(opts);
   })()
}
zx485
  • 28,498
  • 28
  • 50
  • 59
jianxing
  • 39
  • 1