0👍
You are not sending the formData
in post request
.dispatch('createCourse', { course: this.course, formData })
// Only the course object is passed the formData is not used ?? why ?
CourseService.postCourse(course).then(() => {
commit('ADD_COURSE', course)
}).catch(err => console.log(err))
postCourse(course) {
// Same case here only the Course is being posted you haven't used the formData ?
return apiClient.post('/course', course)
}
Actually you are posting the course data in the form of json and only the image in the form of FormData
But this can not be done actually. you can only use JSON
or FormData
in one time So, first you need to add all the entries of the course
object into that formData
object using .append
and the pass the formData
instead of course
.
just like this
.dispatch('createCourse', { course: formData })
Source:stackexchange.com