6

I have my backend app deployed on GAE. Inside it, I am having an API which will upload a file to a GCS bucket. Recently I tried uploading a file of more than 50mb size and got 413 Request entity too large

Did some research and found out that the issue is with ngnix. The API will give 413 for any file > 32Mb.

Found one solution where it was mentioned to include a ngnix.conf file and add client_max_body_size 80M in it. I did so but still getting the same error.

This is my ngnix-app.conf file

server{
 location / {
        client_max_body_size       80m;
        client_body_buffer_size    512k;
  }
}

Anything obvious that I am missing out here?

crtag
  • 2,018
  • 2
  • 14
  • 13
Saptarshi Dey
  • 356
  • 1
  • 4
  • 13
  • You can try adding parameterLimit in your bodyParser app.use(bodyParser.urlencoded({ "limit": "50mb", extended: true, parameterLimit: 1000000 })); This worked for me. – Amir Saleem Apr 30 '18 at 13:26
  • You could also compress the file on the client and de-compress on the server. – Chris Adams Apr 30 '18 at 13:34
  • @ChrisAdams actually the whole thing is happening in backend only. I have a schedule that takes backup of my database every night and then itself call the API to upload the backup SQL file in GCS bucket – Saptarshi Dey Apr 30 '18 at 13:38
  • Ah, yes, missed that in the Q, – Chris Adams Apr 30 '18 at 13:44
  • Please check the second edit [here](https://stackoverflow.com/a/19965089/3058302). You have to modify the maximum size in Node, like this: `app.use(bodyParser.json({limit: '50mb'}));` `app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));` – Mangu May 28 '18 at 07:46
  • similar with: https://stackoverflow.com/questions/27197856/node-nginx-413-request-entity-too-large-client-max-body-size-set/54140202#54140202 – pangpang Jan 11 '19 at 05:10

2 Answers2

11

You can change your request buffer size in your Node.Js application using

app.use(bodyParser.json({limit: '50mb'})); 
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));

Also you can increase your request in nginx configuration

server{
 location / {
        client_max_body_size       xxm;
        client_body_buffer_size    xxm;
  }
}
Kartik Raja S
  • 668
  • 5
  • 18
  • This is actually the answer for anyone coming across this kind of error in GAE with the NodeJs application. I've got HTTP 413 with a JSON payload of a few kilobytes, which is confusing and not mentioned anywhere in official docs. Make sure to include "body-parser" into your project/application as you don't need it by default and it is auto provided by the GAE environment. – crtag Jul 02 '21 at 00:43
  • 1
    using urlencoded doesn't work for multipart/formdata – Pranu Pranav Apr 30 '22 at 11:43
  • @PranuPranav What works for formdata ? – J4GD33P 51NGH Mar 10 '23 at 07:24
2
  1. Just Modify NGINX Configuration File

    sudo nano /etc/nginx/nginx.conf
    
  2. Search for this variable: client_max_body_size. If you find it, then just increase the value to 100M. If you can't find this then just add this line inside HTTP.

    client_max_body_size 100M;
    
  3. To apply changes just restart ngnix

    sudo service nginx restart
    

See screenshot for better understand enter image description here

HandyPawan
  • 1,018
  • 1
  • 11
  • 16