Configure Multer Storage
- Define storage using multer.diskStorage.
- Set the destination to the desired location (public/uploads in this case).
- Set the filename function to create unique filenames (combines field name and timestamp).
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'public/uploads')
},
filename: function (req, file, cb) {
cb(null, file.fieldname + '-' + Date.now())
}
});
const upload = multer({ storage: storage });
Upload Files to Local public folder in NodeJs using Multer
Uploading files to a local public folder in Node.js using Multer involves a few steps. This article helps you set it up.