简体   繁体   English

如何更改 body-parser/express 的最大大小?

[英]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.我尝试使用 express urlencoded 并在那里指定 500 1024 1024,但没有用。 I installed body-parser and tried again, similar and strange behavior here.我安装了 body-parser 并再次尝试,这里出现了类似且奇怪的行为。 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).您可以将此与 Express 4 一起使用来限制请求正文大小/上传文件大小,而不是 express.json() 和 express.urlencoded(),您必须要求 body-parser 模块并使用其 json() 和 urlencoded() 方法, 如果没有为 bodyParser.urlencoded() 显式定义扩展选项,它将抛出警告(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}));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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