Getting error PayloadTooLargeError: request entity too large in case of Using express.Router() Post call
Asked Answered
J

2

7

I am trying to POST call using Router through express but I am getting request entity too large error, can anyone please help to solve the issue?

I want to set mb limit to my POST call payload. I have tried app.use() limit setting through body-parser but seems to get the same issue.

Thanks

Jolenejolenta answered 26/12, 2019 at 7:28 Comment(0)
C
9

The default request size is 100kb in body-parser. try this

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

make sure to add this before defining the routes

Chip answered 26/12, 2019 at 11:55 Comment(1)
thanks @Ajantha Bandara it is working for me after adding line number 1 before defining routes. It will be better if you explained the both lines meaning or please provide the link where this details are provided.Jolenejolenta
R
2

For total noobs like me be sure to either just use bodyParser.json or express.json I had both of these in my code and so no amount of changing body parser helped because it was using express.json to handle requests.

app.use(express.json()); 

const bodyParser = require('body-parser'); 
app.use(bodyParser.json()); 

there is a larger thread for this over on the other link.

Error: request entity too large

Retardment answered 19/2, 2021 at 16:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.