2

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.

Gavin Thomas
  • 1,827
  • 2
  • 11
  • 17
  • 1
    Is the object 1.5 Mb or 1.5 MB? 10 Mb = 10/8 MB = 1.25 MB which is not enough if the object is 1.5 MB. Megabytes and megabits are different. – cbr Sep 25 '20 at 21:45
  • Looks like `nginx` is in between. Make sure that also the nginx configuration for the body size is large enough - it defaults to 1 MB. https://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size – cbr Sep 25 '20 at 21:52

1 Answers1

2

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;

cbr
  • 12,563
  • 3
  • 38
  • 63
  • I did not know I needed to *8. Why is that? I set the jsonLimit to 50mb, the error still occurs. This is a kubernetes deployment via docker. Would I be adjusting the nginx config via my cloud service provider? – Gavin Thomas Sep 25 '20 at 23:37
  • One megabyte (MB) is eight megabits (Mb). – cbr Sep 25 '20 at 23:42
  • `mb` would be `millibits` ;). However, `koa-body` interpretes `mb` as megabyte. I think the issue is nginx config, especially since this only fails in production where nginx is used. – Evert Sep 25 '20 at 23:43
  • This has helped me to look at our ingress controller I setup. This may be the bottleneck right now. – Gavin Thomas Sep 25 '20 at 23:44
  • @GavinThomas If you're using the NGINX Ingress Controller, there appears to be a mechanism to control the configuration via annotations: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#custom-max-body-size – cbr Sep 25 '20 at 23:46
  • While I haven't solved the problem yet, I do believe this is the solution. Thank you for your help! I will update later if it turns out to be something else! – Gavin Thomas Sep 25 '20 at 23:53