loopback icon indicating copy to clipboard operation
loopback copied to clipboard

request entity too large

Open BenjaminHorn opened this issue 11 years ago • 29 comments

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
}

BenjaminHorn avatar Dec 03 '15 18:12 BenjaminHorn

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.

tborja avatar Apr 17 '17 04:04 tborja

"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.

nirmal25990 avatar Jun 02 '17 10:06 nirmal25990

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.

tborja avatar Jun 02 '17 19:06 tborja

Thanks ketansp, your solution was enough for me

buratinodev avatar Oct 27 '17 07:10 buratinodev

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 }} }, ... }

Are there any caveats for increasing this limit?

through-a-haze avatar Oct 16 '18 16:10 through-a-haze

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 avatar Jul 02 '19 14:07 youngtk96

@youngtk96 its works. tks so much

natuan62 avatar Feb 14 '20 09:02 natuan62

@nirmal25990 your fix worked for me too :)

anirudhr95 avatar Jun 11 '20 09:06 anirudhr95

"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.

vivek-kandhvar avatar Jul 15 '20 04:07 vivek-kandhvar