I have a small app that receives via POST a file and stores it in a specific folder.
I know that this line:
const multer = multer({ dest: ‘media' })
(of course with some more code, where I use the multer.single('somefilename')) will create a new folder named media if it doesn't exist already.
But I want to be able to control the name given to the file and some other stuff, so I'm using it with diskStorage instead:
const x = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'media')
},
filename: function (req, file, cb) {
cb(null, file.originalname);
}
})
const multer = multer({ storage: x })
(there's some more code of course with multer.single('somefilename'))
It works fine when the folder 'media' already exists, but doesn't create it if it doesn't - is it supposed to, or only the simpler multer can do that?
Thanks in advance!