📜  multer 文件类型验证 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:51.527000             🧑  作者: Mango

代码示例1
fileFilter: (req,file,callback) => {
        const types = /png|jpg|jpeg|webp|gif|webp|svg/
        const extName = types.test(path.extname(file.originalname).toLocaleLowerCase())
        const mimetype = types.test(file.mimetype)
        if(extName && mimetype){
            callback(null,true)
        } else{
            cb(new Error("Only supported png,jpeg,jpg,gif,webp and svg format image"))
        }
    }