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
In case of postman, try following: Close the postman tab for the API Open a new tab again Rebuild the API request and then send. This may fix the problem. Every time you restart the server you need to do above steps for calling the API again. The reason being multer sends back some cookies … Read more
in product.js: After new Date().toISOString() add replace() to change “:” to an accepted character. Windows OS doesn’t accept files with a “:” The person on Youtube is using MAC OS E.g new Date().toISOString().replace(/:/g, ‘-‘)
[Update Mar 2022] It works perfectly fine till-date and now also shows the uploaded file public URL as well. Complete and working Node Cheat | Upload to s3 using multer-s3 available. Code: var express = require(‘express’), aws = require(‘aws-sdk’), bodyParser = require(‘body-parser’), multer = require(‘multer’), multerS3 = require(‘multer-s3’); aws.config.update({ secretAccessKey: ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’, accessKeyId: ‘XXXXXXXXXXXXXXX’, region: ‘us-east-1’ … 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.