小编Kum*_*Pun的帖子

如何在 multer 中将 cb 错误转换为 json 格式

我正在使用multer在NodeJS中编写图像上传代码

我的代码是

var upload = multer({
    storage: storage,
    limits: {
        fileSize: 1024 * 1024 * 5
    },
    fileFilter: (req, file, cb) => {
        if (file.mimetype == "image/png" || file.mimetype == "image/jpg" || file.mimetype == "image/jpeg") {
            cb(null, true);
        } else {
            return cb(JSON.stringify({ "success": false, "message": "invalid mime type" }), false);

        }
    }
});

router.post('/upload', upload.single('image'), (req, res, next) => {
    const io = req.app.get('io');
    const product = new db.product({
        name: req.body.name,
        category: req.body.category,
        image: req.protocol + …
Run Code Online (Sandbox Code Playgroud)

nodes node.js multer

3
推荐指数
1
解决办法
2413
查看次数

标签 统计

multer ×1

node.js ×1

nodes ×1