Last active
June 12, 2020 17:15
-
-
Save kaungmyatlwin/484b493d56b4223276e454bd6e453f98 to your computer and use it in GitHub Desktop.
Refactoring Multer diskStorage instance using Javascript Closures (before refactor)
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 router = require('express').Router(); | |
const multer = require('multer'); | |
const storage = multer.diskStorage({ | |
destination: (req, file, cb) => { | |
cb(null, './cats'); | |
}, | |
filename: (req, file, cb) => { | |
const fname = `${Date.now()}-${encodeURIComponent(file.originalname)}`; | |
cb(null, fname); | |
}, | |
}); | |
const upload = multer({ storage }); | |
router.post('/', upload.array('photos', 10), (req, res) => { | |
// handle logic | |
}); | |
module.exports = router; |
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 router = require('express').Router(); | |
const multer = require('multer'); | |
const storage = multer.diskStorage({ | |
destination: (req, file, cb) => { | |
cb(null, './dogs'); | |
}, | |
filename: (req, file, cb) => { | |
const fname = `${Date.now()}-${encodeURIComponent(file.originalname)}`; | |
cb(null, fname); | |
}, | |
}); | |
const upload = multer({ storage }); | |
router.post('/', upload.array('photos', 10), (req, res) => { | |
// handle logic | |
}); | |
module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment