Using multer cause error when running app Using multer cause error when running app express express

Using multer cause error when running app


Why multer doesn't create the folder if it doesn't exist??

This is in documentation (link) :

Note: You are responsible for creating the directory when providing destination as a function. When passing a string, multer will make sure that the directory is created for you.

I don't know why the author made this decision, but as you see this is not a bug.

You can use fs module to create directories.


I had the same problem if someone take the error i solved

var storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, 'this is not just /uploads do it like /var/www/....') thank you!!},filename: function (req, file, cb) {cb(null, file.fieldname + '-' + Date.now())}})var upload = multer({ storage: storage });