Uploading multiple files with multer, but from different fields?
What you want is upload.fields(): app.post(‘/rest/upload’, upload.fields([{ name: ‘video’, maxCount: 1 }, { name: ‘subtitles’, maxCount: 1 }]), function(req, res, next){ // … }
What you want is upload.fields(): app.post(‘/rest/upload’, upload.fields([{ name: ‘video’, maxCount: 1 }, { name: ‘subtitles’, maxCount: 1 }]), function(req, res, next){ // … }
I have a workaround for the adding proper extension of files. If you use path node module var multer = require(‘multer’); var path = require(‘path’) var storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, ‘uploads/’) }, filename: function (req, file, cb) { cb(null, Date.now() + path.extname(file.originalname)) //Appending extension } }) var upload = … Read more
You need to use app.use(multer({dest:’./uploads/’})) in the form of one of these: app.use(multer({dest:’./uploads/’}).single(…)); app.use(multer({dest:’./uploads/’}).array(…)); app.use(multer({dest:’./uploads/’}).fields(…)); ie: app.use(multer({dest:’./uploads/’}).single(‘photo’)); And be sure to have something like: <form action=”/postPhotos” enctype=”multipart/form-data” method=”post”> <input type=”file” name=”photo”> <input type=”submit” value=”Upload photo”> </form> In your html.