I am facing an issue with multer where I can upload a single file successfully, but when attempting to upload multiple files it does not work and no files are captured by multer.
I am using formData.append() to send files, but it only manages to upload a single file.
Vue component
const formData = new FormData();
formData.append("productImg", this.imgFile);
this.$store.dispatch(POST_PRODUCT_IMAGE, formData)
.then((response) => {
console.log(response.data);
})
.catch(error => {
console.log(error);
})
Server file
const uploadPath = path.join(__dirname, '/../../public/uploads');
var storage = multer.diskStorage({
destination: (req, file, callback) => {
callback(null, uploadPath + "/garbage/productImg");
},
filename: (req, file, callback) => {
var newName = Date.now() + "_" + file.originalname;
callback(null, newName);
}
});
const upload = multer({
storage: storage
});
productRouter.post('/uploadProductImage', upload.any(), async (req, res) => { // Some Code })
In my attempts to fix the issue, I also tried:
productRouter.post('/uploadProductImage', array('productImg[]', 6), async (req, res) => { // Some Code })
My ultimate goal is to be able to upload multiple files simultaneously to a specific folder.