node.jsreactjskoakoa-bodyparser

Cannot HTTPS POST json object at 1.5 mb via Koa and koa-body. Status 413 production only


I am attempting to upload a JSON object at about 1.5 mb from our React client to our Koa.js node.js server.

I am using Koa.js with koaBody (koa-body 4.1.1).

On HTTPS, in our production environment, I cannot upload the object, I receive a status of 413 from our server. However, in dev or on http, I have no problem uploading the file. I can change the jsonLimit to '1mb' and replicate the same error in dev, so I know the formatting is correct.

I have setup the configuration to handle up to '10mb'. Here is the code.

.use(koaBody({
  multipart: true,
  json: true,
  jsonLimit: "10mb",
}))

Does anybody have any solutions? I will simply split out the JSON object, however I'd like to know 'why' this isn't working, as to me 1.5 mb isn't too large. enter image description here

UPDATE: I have set the jsonLimit to '50mg' with no difference in the outcome.

UPDATE: I believe this 413 is related to the ingress controller we have setup via azure.


Solution

  • Looking at your screenshot, the body size is indeed around 1.5MB (megabytes), but that's 1.5*8= ~12.5 Mb (megabits). So raise the jsonLimit to accomodate for this.

    There's also nginx between your browser and your application. You'll need to make sure that nginx' body size limit is also high enough. Find client_max_body_size in your configurations - or if it doesn't exist, set it for your application (e.g. client_max_body_size 20m;