问题
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