Sails.js bodyParser - request entity too large on version 0.10.5

血红的双手。 提交于 2019-12-19 09:23:09

问题


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!


回答1:


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);
  }
}



回答2:


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);
   })()
}


来源:https://stackoverflow.com/questions/28460135/sails-js-bodyparser-request-entity-too-large-on-version-0-10-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!