Created
September 12, 2022 10:16
-
-
Save MohitGupta121/35d8b5428cc2abc2154f95a4ad0eb82d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const storage = multer.diskStorage({ | |
destination: (req, file, cb) => { | |
cb(null, 'Images') | |
}, | |
filename: (req, file, cb) => { | |
cb(null, Date.now() + path.extname(file.originalname)) | |
} | |
}) | |
const upload = multer({ | |
storage: storage, | |
limits: { fileSize: '1000000' }, | |
fileFilter: (req, file, cb) => { | |
const fileTypes = /jpeg|jpg|png|gif/ | |
const mimeType = fileTypes.test(file.mimetype) | |
const extname = fileTypes.test(path.extname(file.originalname)) | |
if(mimeType && extname) { | |
return cb(null, true) | |
} | |
cb('Give proper files formate to upload') | |
} | |
}).single('image') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment