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
}
It seems that there is a 1MB limit in the Cloudant request.
https://github.com/cloudant/java-cloudant/issues/345
It is just weird that this limit is there without a way to change it.
"parse": {
"body-parser#json": {
"params": {
"strict": false,
"limit": "50mb"
}
},
"body-parser#urlencoded":{
"params": {
"extended": true,
"limit": "50mb"
}
}
}
Changes in config.json doesn't working for me. But making changes in middleware.json resolve my issue.
Thanks nirmal25990, but IBM confirmed that middleware.json fixes won't fix the issue because it is Cloudant that has a 1MB limit on it's entities. They suggest either using an attachment in Cloudant or use an ObjectStore.
Thanks ketansp, your solution was enough for me
I got it working by modifying values in
middleware.jsonfile. You can set the actual request limit there. Apparently loopback picks it up frommiddleware.json, notconfig.json.
{ ..., "parse": { "body-parser#json": { "params" : { "limit" : "50mb"}}, "body-parser#urlencoded": {"params": { "limit" : "50mb", "extended": true }} }, ... }
Are there any caveats for increasing this limit?
If you are hosting the server on NGINX try the following
Modify NGINX Configuration File
sudo nano /etc/nginx/nginx.conf Search for this variable: client_max_body_size. If you find it, just increase its size to 100M, for example. If it doesn’t exist, then you can add it inside and at the end of http
client_max_body_size 100M; Restart nginx to apply the changes.
sudo service nginx restart
@youngtk96 its works. tks so much
@nirmal25990 your fix worked for me too :)
"parse": { "body-parser#json": { "params": { "strict": false, "limit": "50mb" } }, "body-parser#urlencoded":{ "params": { "extended": true, "limit": "50mb" } } }Changes in config.json doesn't working for me. But making changes in middleware.json resolve my issue.
Unless you override parse param in middleware.json, by using a body-parser, setting it in config.js will work. It does work for us.