TypeError: Cannot read property 'filename' of undefined 'getting this error while creating a User' TypeError: Cannot read property 'filename' of undefined 'getting this error while creating a User' mongoose mongoose

TypeError: Cannot read property 'filename' of undefined 'getting this error while creating a User'


To send files along with other data from the frontend, you need to use the FormData API. With a user object and axios, I'd do something like this:

const formData = new FormData();// Append all properties of the `user` object to the formfor (const [key, value] of Object.entries(user)) {  formData.append(key, value);}const response = await axios.post('/signup', formData, {  headers: {    // Multer only parses "multipart/form-data" requests    'Content-Type': 'multipart/form-data',  },});