request entity too large
If I try to send a json to the server, which is about 220kb. (It contains a base64 coded image as a long string). I am getting the following error:
{"errors":[{"status":413,"source":"","title":"Error","code":"","detail":"request entity too large"}]}
server/confing.json
{
"restApiRoot": "/api",
"host": "0.0.0.0",
"port": 3001,
"remoting": {
"context": {
"enableHttpContext": false
},
"rest": {
"normalizeHttpPath": false,
"xml": false
},
"json": {
"strict": false,
"limit": "50mb"
},
"urlencoded": {
"extended": true,
"limit": "50mb"
},
"cors": false,
"errorHandler": {
"disableStackTrace": false
}
},
"legacyExplorer": false
}
Do you have a json parser set up in the middleware.json or server.js?
Thanks,
Raymond Feng ([email protected]) Co-Founder and Architect @ StrongLoop, Inc. (An IBM Company)
StrongLoop http://strongloop.com/ makes it easy to develop APIs http://strongloop.com/mobile-application-development/loopback/ in Node, plus get DevOps capabilities http://strongloop.com/node-js-performance/strongops/ like monitoring, debugging and clustering.
On Dec 3, 2015, at 10:29 AM, BenjaminHorn [email protected] wrote:
If I try to send a json to the server, which is about 220kb. (It contains a base64 coded image as a long string). I am getting the following error:
{"errors":[{"status":413,"source":"","title":"Error","code":"","detail":"request entity too large"}]}
server/confing.json
{ "restApiRoot": "/api", "host": "0.0.0.0", "port": 3001, "remoting": { "context": { "enableHttpContext": false }, "rest": { "normalizeHttpPath": false, "xml": false }, "json": { "strict": false, "limit": "50mb" }, "urlencoded": { "extended": true, "limit": "50mb" }, "cors": false, "errorHandler": { "disableStackTrace": false } }, "legacyExplorer": false } — Reply to this email directly or view it on GitHub https://github.com/strongloop/loopback/issues/1856.
I did not alter any of those files. They look like this:
server.js
var loopback = require('loopback');
var boot = require('loopback-boot');
var app = module.exports = loopback();
app.start = function() {
// start the web server
return app.listen(function() {
app.emit('started');
var baseUrl = app.get('url').replace(/\/$/, '');
console.log('Web server listening at: %s', baseUrl);
if (app.get('loopback-component-explorer')) {
var explorerPath = app.get('loopback-component-explorer').mountPath;
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
}
});
};
// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname, function(err) {
if (err) throw err;
// start the server if `$ node server.js`
if (require.main === module)
app.start();
});
middleware.json
{
"initial:before": {
"loopback#favicon": {}
},
"initial": {
"compression": {},
"cors": {
"params": {
"origin": true,
"credentials": true,
"maxAge": 86400
}
}
},
"session": {},
"auth": {},
"parse": {},
"routes": {
"loopback#rest": {
"paths": [
"${restApiRoot}"
]
}
},
"files": {},
"final": {
"loopback#urlNotFound": {}
},
"final:after": {
"loopback#errorHandler": {}
}
}
@raymondfeng is there any news on this?
Hey @BenjaminHorn , do you have an sample repo from which I can reproduce the issue? You can follow this guide which basically says to fork the loopback-sandbox and reproduce your issue in the fork, but any sample repo will do.
If I am not mistaken, you should be able to use a Node.js buffer object to transfer binary data instead of a string. I don't know your particular use case though.
@richardpringle @raymondfeng After some investigation I found that the problem is the content type. If I try to Post with
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
then it works. My client (ember) app sends
contentType: 'application/vnd.api+json'
then the new limit has no effect.
Setting the type wont fix it. I know that is not in the strongloop documentation, only in https://www.npmjs.com/package/body-parser#type-2 server/config.json
...
"remoting": {
"context": {
"enableHttpContext": false
},
"rest": {
"normalizeHttpPath": false,
"xml": false
},
"json": {
"strict": false,
"limit": "50mb"
"type": "application/vnd.api+json"
},
...
I believe this is an issue with loopback-component-jsonapi. Needs a quick fix. https://github.com/digitalsadhu/loopback-component-jsonapi/blob/master/lib/headers.js#L33 Needs to not overwrite but rather merge with options defined elsewhere (link in config.json) Does that sound like its the issue @BenjaminHorn ?
thanks @digitalsadhu that was the issue indeed. I made a PR.
What's the fix on this? I am running loopback on Bluemix. I am getting the Request too large error using swagger js client.
Also running into the same error
+1 As am I
Have you adjusted the limit per https://loopback.io/doc/en/lb2/config.json.html?
Hello,
This is my config.json
{ "restApiRoot": "/api", "host": "0.0.0.0", "port": 3000, "remoting": { "context": false, "rest": { "normalizeHttpPath": false, "xml": false }, "json": { "strict": false, "limit": "80mb" }, "urlencoded": { "extended": true, "limit": "50mb" }, "cors": false, "handleErrors": false }, "legacyExplorer": false }
I checked where the error message Request Entity Too Large occurs and it is in here: from /node-modules/raw-body/index.js
function readStream (stream, encoding, length, limit, callback) { var complete = false var sync = true
// check the length and limit options. // note: we intentionally leave the stream paused, // so users should handle the stream themselves. if (limit !== null && length !== null && length > limit) { return done(createError(413, 'request entity too large', 'entity.too.large', { expected: length, length: length, limit: limit })) }
Does anybody know which configuration file this picks up the options for limit and length from?
I found that the limit value is picked up from server.js
Serpentinefire,
Can you supply the code on server.js to fix this issue?
If you're using bodyParser, Try put that where you configure your express in the application. app.use(bodyParser({ limit: '10mb' }));
I already have this on my server.js and I still get the error.
`var bodyParser = require('body-parser');
app.use( bodyParser.json({limit: '50mb'}) ); app.use(bodyParser.urlencoded({ limit: '50mb', extended: true, parameterLimit:50000 }));`
I got it working by modifying values in middleware.json file. You can set the actual request limit there. Apparently loopback picks it up from middleware.json, not config.json.
{
...,
"parse": {
"body-parser#json": { "params" : { "limit" : "50mb"}},
"body-parser#urlencoded": {"params": { "limit" : "50mb", "extended": true }}
},
...
}

@tborja Inside the folder node_modules you can find this folder. try change this value limit (i.e limit: '50mb') for the type of data that you send, and see if it works for you. If don't work the problem is not with body parser. If work your body-parse configuration is in the wrong place
Hello mnvini,
I did as you suggested and changed the limit parameter for the types on body-parser, but I am still getting the same entity too large error.
My loopback database is Cloudand on Bluemix and I am using this connector: "loopback-connector-cloudant": "^1.2.2"
It seems that it is the cloudant server that is sending out the entity too large error.
{"error":{"name":"Error","status":413,"message":"the request entity is too large","error":"too_large","reason":"the request entity is too large","scope":"couch","statusCode":413,"request":{"method":"POST","headers":{"content-type":"application/json","accept":"application/json"},"uri":"https://XXXXXX:[email protected]/shoenvious-server","body":"{\"type\":\"Right\",\"subComponentID\":\"a31a037e508571d5301b5eddfdce5e86\",\"webGL\":\"{\\n \\\"metadata\\\":{\\n \\\"version\\\":3,\\n \\\"faces\\\":10960,\\n \\\"normals\\\":10956,\\n \\\"generator\\\":\\\"io_three\\\",\\n \\\"uvs\\\":1,\\n \\\"vertices\\\":10956,\\n \\\"type\\\":\\\"Geometry\\\"\\n },\\n \\\"faces\\\":[41,0,4,5,1,0,1,2,3,0,1,2,3,41,1,5,7490,7489,3,2,4,5,3,2,4,5,41,4,6223,6222,5,1,6,7,2,1,6,7,2,41,5,6222,10509,7490,2,7,8,4,2,7,8,4,41,0,1,6,2,0,3,9,10,0,3,9,10,41,2,6,7377,7378,10,9,11,12,10,9,11,12,41,1,7489,7488,6,3,5,13,9,3,5,13,9,41,6,7488,10510,7377,9,13,14,11,9,13,14,11,41,0,2,7,3,0,10,15,16,0,10,15,16,41,3,7,6174,6175,16,15,17,18,16,15,17,18,41,2,7378,7379,7,10,12,19,15,10,12,19,15,41,7,7379,10275,6174,15,19,20,17,15,19,20,17,41,0,3,8,4,0,16,21,1,0,16,21,1,41,4,8,6224,6223,1,21,22,6,1,21,22,6,41,3,6175,6176,8,16,18,23,21,16,18,23,21,41,8,6176,10281,6224,21,23,24,22,21,23,24,22,41,9,13,14,10,25,26,27,28,25,26,27,28,41,10,14,7526,7525,28,27,29,30,28,27,29,30,41,13,7471,7470,14,26,31,32,27,26,31,32,27,41,14,7470,10518,7526,27,32,33,29,27,32,33,29,41,9,10,15,11,25,28,34,35,25,28,34,35,41,11,15,6213,6214,35,34,36,37,35,34,36,37,41,10,7525,7524,15,28,30,38,34,28,30,38,34,41,15,7524,10517,6213,34,38,39,36,34,38,39,36,41,9,11,16,12,25,35,40,41,25,35,40,41,41,12,16,6170,6169,41,40,42,43,41,40,42,43,41,11,6214,6215,16,35,37,44,40,35,37,44,40,41,16,6215,10278,6170,40,44,45,42,40,44,45,42,41,9,12,17,13,25,41,46,26,25,41,46,26,41,13,17,7472,7471,26,46,47,31,26,46,47,31,41,12,6169,6168,17,41,43,48,46,41,43,48,46,41,17,6168,10274,7472,46,48,49,47,46,48,49,47,41,18,22,23,19,50,51,52,53,50,51,52,53,41,19,23,7499,7498,53,52,54,55,53,52,54,55,41,22,7309,7308,23,51,56,57,52,51,56,57,52,41,23,7308,10511,7499,52,57,58,54,52,57,58,54,41,18,19,24,20,50,53,59,60,50,53,59,60,41,20,24,7496,7495,60,59,61,62,60,59,61,62,41,19,7498,7497,24,53,55,63,59,53,55,63,59,41,24,7497,10512,7496,59,63,64,61,59,63,64,61,41,18,20,25,21,50,60,65,66,50,60,65,66,41,21,25,6177,6178,66,65,67,68,66,65,67,68,41,20,7495,7494,25,60,62,69,65,60,62,69,65,41,25,7494,10276,6177,65,69,70,67,65,69,70,67,41,18,21,26,22,50,66,71,51,50,66,71,51,41,22,26,7310,7309,51,71,72,56,51,71,72,56,41,21,6178,6179,26,66,68,73,71,66,68,73,71,41,26,6179,10282,7310,71,73,74,72,71,73,74,72,41,27,32,33,28,75,76,77,78,75,76,77,78,41,28,33,6171,6172,78,77,79,80,78,77,79,80,41,32,6181,6182,33,76,81,82,77,76,81,82,77,41,33,6182,10279,6171,77,82,83,79,77,82,83,79,41,27,28,34,29,75,78,84,85,75,78,84,85,41,29,34,6687,6688,85,84,86,87,85,84,86,87,41,28,6172,6173,34,78,80,88,84,78,80,88,84,41,34,6173,10422,6687,84,88,89,86,84,88,89,86,41,27,29,35,30,75,85,90,91,75,85,90,91,41,30,35,6615,6616,91,90,92,93,91,90,92,93,41,29,6688,6689,35,85,87,94,90,85,87,94,90,41,35,6689,10368,6615,90,94,95,92,90,94,95,92,41,27,30,36,31,75,91,96,97,75,91,96,97,41,31,36,7473,7474,97,96,98,99,97,96,98,99,41,30,6616,6617,36,91,93,100,96,91,93,100,96,41,36,6617,10366,7473,96,100,101,98,96,100,101,98,41,27,31,37,32,75,97,102,76,75,97,102,76,41,32,37,6180,6181,76,102,103,81,76,102,103,81,41,31,7474,7475,37,97,99,104,102,97,99,104,102,41,37,7475,10283,6180,102,104,105,103,102,104,105,103,41,38,42,43,39,106,107,108,109,106,107,108,109,41,39,43,6219,6220,109,108,110,111,109,108,110,111,41,42,7432,7431,43,107,112,113,108,107,112,113,108,41,43,7431,10273,6219,108,113,114,110,108,113,114,110,41,38,39,44,40,106,109,115,116,106,109,115,116,41,40,44,7290,7291,116,115,117,118,116,115,117,118,41,39,6220,6221,44,109,111,119,115,109,111,119,115,41,44,6221,10367,7290,115,119,120,117,115,119,120,117,41,38,40,45,41,106,116,121,122,106,116,121,122,41,41,45,7440,7441,122,121,123,124,122,121,123,124,41,40,7291,7292,45,116,118,125,121,116,118,125,121,41,45,7292,10490,7440,121,125,126,123,121,125,126,123,41,38,41,46,42,106,122,127,107,106,122,127,107,41,42,46,7433,7432,107,127,128,112,107,127,128,112,41,41,7441,7442,46,122,124,129,127,122,124,129,127,41,46,7442,10285,7433,127,129,130,128,127,129,130,128,41,47,51,52,48,131,132,133,134,131,132,133,134,41,48,52,6176,6175,134,133,23,18,134,133,23,18,41,51,6196,6195,52,132,135,136,133,132,135,136,133,41,52,6195,10281,6176,133,136,24,23,133,136,24,23,41,47,48,53,49,131,134,137,138,131,134,137,138,41,49,53,6164,6163,138,137,139,140,138,137,139,140,41,48,6175,6174,53,134,18,17,137,134,18,17,137,41,53,6174,10275,6164,137,17,20,139,137,17,20,139,41,47,49,54,50,131,138,141,142,131,138,141,142,41,50,54,6198,6199,142,141,143,144,142,141,143,144,41,49,6163,6162,54,138,140,145,141,138,140,145,141,41,54,6162,10288,6198,141,145,146,143,14…7,-1.59764,0.491442,0.399367,-1.58884,0.502319,0.494112,-1.56082,0.487188,0.242472,-1.60173,0.4885,0.214085,-1.59872,0.489335,0.199799,-1.59632,0.590356,0.866999,-1.39705,0.71764,1.3198,-1.13526,0.813313,1.75801,-0.939161,0.899797,2.23535,-0.7631,0.490321,0.188987,-1.59376,0.531718,0.650192,-1.49754,0.485936,0.311768,-1.6033,0.655607,1.09493,-1.26548,0.854753,1.98605,-0.856086,0.88273,2.15222,-0.800525,0.376752,-0.305051,-0.683632,0.34063,0.031877,-0.656447,0.365228,-0.06284,-0.682236,0.381245,-0.225592,-0.692264,0.383504,-0.262841,-0.688468,0.384004,-0.29107,-0.685408,0.324488,0.412005,-0.523214,0.531449,0.82227,-0.221296,0.788544,1.10898,0.206926,0.951543,1.3543,0.559693,0.382337,-0.307698,-0.685168,0.307321,0.187573,-0.598008,0.375894,-0.148598,-0.690133,0.410188,0.633316,-0.386476,0.865698,1.22441,0.374418,0.919869,1.30346,0.487582,1.65505,-0.328195,-1.20446,1.6959,0.007126,-1.18566,1.66855,-0.083895,-1.19466,1.6504,-0.246849,-1.20547,1.65138,-0.284317,-1.20285,1.65155,-0.313078,-1.19955,1.73065,0.383194,-1.0971,1.81081,0.797877,-0.74005,1.91268,1.08647,-0.247482,2.07388,1.33019,0.103797,1.65101,-0.330041,-1.20044,1.72656,0.157508,-1.16131,1.65436,-0.169324,-1.20058,1.77114,0.604445,-0.940439,1.98795,1.20066,-0.079105,2.04,1.27946,0.033336,0.585394,1.07904,-0.20416,0.641363,1.45515,-0.828607,0.534953,1.29905,-0.486452,1.32277,1.44089,-1.10559,1.78429,1.06654,-0.674593,1.62465,1.27928,-0.926082,1.0903,1.53068,-1.1646,0.767124,1.53751,-1.03334,1.89491,0.835347,-0.30992,0.632634,0.933515,-0.079711,0.664993,0.799856,0.006146,1.8968,1.14228,-0.395864,1.8557,1.18658,-0.511461,1.92809,1.35298,-0.321,1.88314,1.4005,-0.436835,1.88185,1.0924,-0.410448,1.84386,1.13999,-0.526744,0.70242,1.37975,0.161347,0.657608,1.42641,0.045812,0.678158,1.16106,0.08605,0.624984,1.20624,-0.024769,0.677046,1.11369,0.067347,0.622941,1.16214,-0.042613,0.65671,0.5068,-1.6867,0.647659,0.413155,-1.70677,0.640596,0.259481,-1.71729,0.642787,0.233226,-1.71105,0.645359,0.217823,-1.70488,0.716106,0.894596,-1.55604,0.831524,1.34533,-1.3129,0.917819,1.78481,-1.15501,0.646391,0.195867,-1.70244,0.675127,0.668514,-1.64594,0.640201,0.321903,-1.72087,0.776219,1.14323,-1.42915,0.973224,2.02418,-1.02863,0.993471,2.16361,-0.984523,0.798615,0.505015,-1.71162,0.790562,0.409708,-1.73668,0.783585,0.256953,-1.75543,0.785568,0.231153,-1.75339,0.788856,0.215761,-1.74896,0.8534,0.885956,-1.55562,0.963252,1.33496,-1.29837,1.04927,1.75026,-1.13794,0.8171,0.661965,-1.65623,0.783802,0.318197,-1.75168,0.910496,1.12934,-1.41528,1.10052,2.01595,-1.01371,1.12386,2.15158,-0.974662,0.535801,0.401556,-1.6424,0.546576,0.492096,-1.62173,0.522539,0.259653,-1.65554,0.521633,0.234634,-1.65325,0.522009,0.218893,-1.64937,0.619576,0.878668,-1.46863,0.744252,1.31897,-1.22668,0.827908,1.74846,-1.0587,0.737392,0.194145,-1.73145,0.572774,0.65147,-1.56807,0.52753,0.316862,-1.65416,0.689316,1.11746,-1.33556,0.885787,2.00277,-0.937988,0.906549,2.13007,-0.895905,0.569333,0.195283,-1.66813,1.03381,2.29555,-0.900465,1.15088,2.2753,-0.908859,0.943096,2.27527,-0.841442,1.02078,2.27425,-0.926825,1.15444,2.25405,-0.924958,0.923416,2.24211,-0.850813,1.0093,2.24063,-0.952373,1.14427,2.22214,-0.946868,0.917317,2.1978,-0.868003,1.15156,2.24293,-0.935292,0.920525,2.22781,-0.856538,1.01651,2.26347,-0.936956,1.1584,2.26573,-0.919486,0.929065,2.26059,-0.8438,1.02393,2.29113,-0.92194,0.647875,0.199501,-1.69836,0.782184,0.19617,-1.74173,0.530584,0.198554,-1.64845,0.851684,1.43813,-1.2766,0.985579,1.42947,-1.25788,0.768408,1.41107,-1.1859,1.00505,1.57615,-1.21795,0.792829,1.56268,-1.13747,0.870099,1.59689,-1.24706,1.03646,1.70308,-1.15986,0.8167,1.69747,-1.08511,0.901574,1.73429,-1.18833,0.949082,1.87359,-1.08306,1.07607,1.85197,-1.07591,0.859055,1.8432,-0.997042,1.08692,1.92603,-1.04501,0.872308,1.91522,-0.968175,0.959343,1.94128,-1.05675,0.933102,1.82824,-1.12027,1.0613,1.80001,-1.11122,0.842305,1.79748,-1.02784,0.882176,1.6542,-1.22769,1.01741,1.63189,-1.19802,0.802749,1.60922,-1.12284,1.02766,1.66979,-1.17802,0.810736,1.65643,-1.10352,0.891764,1.69587,-1.20902,0.85654,1.51719,-1.27214,0.994249,1.50381,-1.24082,0.77816,1.4805,-1.16763,0.99911,1.53772,-1.23142,0.785087,1.52108,-1.15141,0.862617,1.55464,-1.26036,0.854941,1.48089,-1.27455,0.990967,1.47045,-1.24813,0.774509,1.44886,-1.17404],\\n \\\"name\\\":\\\"Cube.005Geometry.1\\\"\\n}\\n\",\"shoeID\":\"369608a006044277f877f0675afd935e\",\"componentID\":\"d13b3e6fda9177bf3765860b968d36a2\",\"loopback__model__name\":\"SubcomponentWebGL\"}"},"headers":{"cache-control":"must-revalidate","content-type":"application/json","date":"Wed, 12 Apr 2017 02:44:10 GMT","x-couch-request-id":"18ed3d69c1","x-couchdb-body-time":"0","x-content-type-options":"nosniff","x-cloudant-backend":"bm-cc-dal-01","via":"1.1 lb1.bm-cc-dal-01 (Glum/1.34.0)","strict-transport-security":"max-age=31536000","statusCode":413,"uri":"https://XXXXXX:[email protected]/shoenvious-server"},"errid":"non_200","description":"**couch returned 413**"}}
"couch returned 413"
I am sending to Cloudant webGL as part of the json msg since the loopback connector does not support cloudant attachments. I guess I will have to find out where to increase the entity limit in cloudant.
Thanks for all your help guys.