【问题标题】:Request entity too Large while uploading image files using multer使用 multer 上传图像文件时请求实体太大
【发布时间】: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'

我查看了我所有的代码,并且只需要大量的证据来证明我想要的更多,这将揭示我的大部分项目。

如何处理这个错误。

【问题讨论】:

标签: node.js express multer


【解决方案1】:

你能不能试试,允许限制ar body parser

app.use(bodyParser.json({limit:'5mb'})); 
app.use(bodyParser.urlencoded({extended:true, limit:'5mb'}));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-27
    • 1970-01-01
    • 2021-02-11
    • 2021-06-18
    • 2014-08-09
    • 2018-07-07
    相关资源
    最近更新 更多