Created
October 24, 2019 17:11
-
-
Save joshtrigger/c383221d7be335e989eb820c2494975d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 multer = require('multer'); | |
const storage = multer.diskStorage({ | |
destination: function (req, file, cb) { | |
cb(null, './uploads/') | |
}, | |
filename: function (req, file, cb) { | |
cb(null, new Date().toISOString() + '-' + file.originalname) | |
} | |
}) | |
const fileFilter = (req, file, cb) => { | |
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png') { | |
cb(null, true) | |
} else { | |
//reject file | |
cb({message: 'Unsupported file format'}, false) | |
} | |
} | |
const upload = multer({ | |
storage: storage, | |
limits: { fileSize: 1024 * 1024 }, | |
fileFilter: fileFilter | |
}) | |
module.exports = upload; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment