multer rename file

Solutions on MaxInterview for multer rename file by the best coders in the world

showing results for - "multer rename file"
Bently
06 Jan 2020
1const multer = require('multer')
2
3const storage = multer.diskStorage({
4    destination: function (req, file, cb) {
5        cb(null, 'uploads/')
6    },
7    filename: function (req, file, cb) {
8        cb(null, file.filename + '-' + Date.now())
9  	}
10})
11
12const upload = multer({ storage: storage })
13
14// For Single uploads
15router.route('/upload').post(upload.single('file'), (req, res, next) => { return res.json(req.file) })
16
17// For multiple file uploads (using FormData)
18router.route('/upload').post(upload.array('file[]'), (req, res, next) => { return res.json(req.file) })