0

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

Shahaji
  • 45
  • 11

2 Answers2

0

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

Ajantha Bandara
  • 1,153
  • 10
  • 25
  • 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. – Shahaji Dec 27 '19 at 05:54
0

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