Answers for "multer rename file"

0

multer rename file

const multer = require('multer')

const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, 'uploads/')
    },
    filename: function (req, file, cb) {
        cb(null, file.filename + '-' + Date.now())
  	}
})

const upload = multer({ storage: storage })

// For Single uploads
router.route('/upload').post(upload.single('file'), (req, res, next) => { return res.json(req.file) })

// For multiple file uploads (using FormData)
router.route('/upload').post(upload.array('file[]'), (req, res, next) => { return res.json(req.file) })
Posted by: Guest on March-29-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language