Skip to content

Instantly share code, notes, and snippets.

@MohitGupta121
Created September 12, 2022 10:16
Show Gist options
  • Save MohitGupta121/35d8b5428cc2abc2154f95a4ad0eb82d to your computer and use it in GitHub Desktop.
Save MohitGupta121/35d8b5428cc2abc2154f95a4ad0eb82d to your computer and use it in GitHub Desktop.
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