使用 multer 上传图像文件时请求实体太大
Request entity too Large while uploading image files using multer
var storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, '/uploadedProfilePics')
},
filename: (req, file, cb) => {
cb(null, file.fieldname + "-" + Date.now() + "-" + file.originalname)
}
});
var upload = multer({storage: storage});
使用 multer 将图像文件上传到 express 服务器时出错
> PayloadTooLargeError: request entity too large
> at readStream (/node_modules/raw-body/index.js:155:17)
> at getRawBody (/node_modules/raw-body/index.js:108:12)
> at read (/node_modules/body-parser/lib/read.js:77:3)
> at urlencodedParser (/node_modules/body-parser/lib/types/urlencoded.js:116:5)
> at Layer.handle [as handle_request] (/node_modules/express/lib/router/layer.js:95:5)
> at trim_prefix (/node_modules/express/lib/router/index.js:317:13)
> at /node_modules/express/lib/router/index.js:284:7
> at Function.process_params (/node_modules/express/lib/router/index.js:335:12)
> at next (/node_modules/express/lib/router/index.js:275:10)
> at jsonParser (/node_modules/body-parser/lib/types/json.js:119:7)
> message: 'request entity too large', expected: 299371, length:
> 299371, limit: 102400, type: 'entity.too.large'
我检查了我所有的代码,只需要足够多的证据来展示我想要的东西,而不是揭示我的项目的大部分内容。
如何处理这个错误。
你能试试吗,允许limit ar body parser
app.use(bodyParser.json({limit:'5mb'}));
app.use(bodyParser.urlencoded({extended:true, limit:'5mb'}));
var storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, '/uploadedProfilePics')
},
filename: (req, file, cb) => {
cb(null, file.fieldname + "-" + Date.now() + "-" + file.originalname)
}
});
var upload = multer({storage: storage});
使用 multer 将图像文件上传到 express 服务器时出错
> PayloadTooLargeError: request entity too large
> at readStream (/node_modules/raw-body/index.js:155:17)
> at getRawBody (/node_modules/raw-body/index.js:108:12)
> at read (/node_modules/body-parser/lib/read.js:77:3)
> at urlencodedParser (/node_modules/body-parser/lib/types/urlencoded.js:116:5)
> at Layer.handle [as handle_request] (/node_modules/express/lib/router/layer.js:95:5)
> at trim_prefix (/node_modules/express/lib/router/index.js:317:13)
> at /node_modules/express/lib/router/index.js:284:7
> at Function.process_params (/node_modules/express/lib/router/index.js:335:12)
> at next (/node_modules/express/lib/router/index.js:275:10)
> at jsonParser (/node_modules/body-parser/lib/types/json.js:119:7)
> message: 'request entity too large', expected: 299371, length:
> 299371, limit: 102400, type: 'entity.too.large'
我检查了我所有的代码,只需要足够多的证据来展示我想要的东西,而不是揭示我的项目的大部分内容。
如何处理这个错误。
你能试试吗,允许limit ar body parser
app.use(bodyParser.json({limit:'5mb'}));
app.use(bodyParser.urlencoded({extended:true, limit:'5mb'}));