Created
November 26, 2020 14:20
-
-
Save lazycipher/0a6ad30bc925ecdb0e56ef1cae169051 to your computer and use it in GitHub Desktop.
Convert File to buffer using multer
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
// type of files allowed | |
const fileFilter = (req, file, cb) => { | |
if (file.originalname.match(/\.(jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF)$/)) { | |
cb(null, true) | |
} else { | |
cb(null, false) | |
} | |
} | |
const storage = multer.memoryStorage() | |
exports.processFile = multer({ | |
storage: storage, | |
limits: { | |
fileSize: 1024 * 1024 * 10 // 10 mb | |
}, | |
fileFilter: fileFilter, | |
upload: (err) => { | |
if (err instanceof multer.MulterError) { | |
throw new Error('error in uploading ' + err) | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment