【发布时间】:2021-07-01 12:46:36
【问题描述】:
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 将图像文件上传到快递服务器时出错
> 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'
我查看了我所有的代码,并且只需要大量的证据来证明我想要的更多,这将揭示我的大部分项目。
如何处理这个错误。
【问题讨论】:
-
您要上传的文件大小是多少?
-
从以下链接检查限制选项 - github.com/expressjs/multer#multeropts