Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change max size for body-parser/express?

I have an application that complains that the file size is too large. I tried using express urlencoded and specifying 50010241024 there, it didn't work. I installed body-parser and tried again, similar and strange behavior here. Please tell me how can I fix this?

app.use(bodyParser.json({ limit: 500*1024*1024, extended: true }));
app.use(bodyParser.urlencoded({ limit: 500*1024*1024, extended: true }));
like image 382
Someone Avatar asked Jan 26 '26 13:01

Someone


1 Answers

You can use this with Express 4 to limit request body size/Upload file size, instead of express.json() and express.urlencoded(), you must require the body-parser module and use its json() and urlencoded() methods, if the extended option is not explicitly defined for bodyParser.urlencoded(), it will throw a warning (body-parser deprecated undefined extended: provide extended option).

var bodyParser = require('body-parser');
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
like image 160
Dixit Chotaliya Avatar answered Jan 28 '26 07:01

Dixit Chotaliya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!