I want to send a images folder along with the other data. (name and openingHours);
this is my vuejs code that I use to submit data to the backend
const formData = new FormData();
formData.append("name", this.name);
formData.append("openingHours", this.openingHours);
formData.append("photos", this.selectedFile);
await this.$http.post("spa", formData);
Here my controller code
var multer = require('multer')
var upload = multer({ dest: 'uploads/' })
router.post('/', upload.array('photos', 10), async (req, res) => {
console.log(req.file);
console.log(req.body);
});
Here the req.file is undefined and photos also come under the body and also this openingHours is not an array. I pass and array in the front-end.
This is my body parser settings in the app.js
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json());
Can anybody tell me what's wrong with my code?
I want to pass openingHours as an JS array.
UPDATED
this is what I get if I console log openingHours in that method.
this.openingHours
and what is it bound to? - Mat J