Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

multer file type validation

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"))
        }
    }
 
PREVIOUS NEXT
Tagged: #multer #file #type #validation
ADD COMMENT
Topic
Name
4+7 =