简体   繁体   中英

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 500 1024 1024 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 }));

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}));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM