HTTP 413 Request Entity Too Large in Node JS Project in GAE
Asked Answered
B

2

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?

Bybee answered 30/4, 2018 at 13:24 Comment(6)
You can try adding parameterLimit in your bodyParser app.use(bodyParser.urlencoded({ "limit": "50mb", extended: true, parameterLimit: 1000000 })); This worked for me.Expressman
You could also compress the file on the client and de-compress on the server.Recti
@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 bucketBybee
Ah, yes, missed that in the Q,Recti
Please check the second edit here. 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}));Barrie
similar with: #27198356Strychninism
S
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;
  }
}
Selfimmolating answered 23/4, 2019 at 10:53 Comment(3)
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.Tot
using urlencoded doesn't work for multipart/formdataPenutian
@PranuPranav What works for formdata ?Howell
W
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

Wedurn answered 13/11, 2021 at 20:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.