i try to upload image on the Nodejs server i try to upload image on the Nodejs server mongoose mongoose

i try to upload image on the Nodejs server


Seeing your error stacktrace, it is clear that the file object in your request body is undefined, hence, trying to access filename of undefined throwsCannot read property 'filename' of undefined

The issue is with your method of sending file data to server from Angular. Your form need to have enctype="multipart/formdata" normally to overcome such issues. Luckily, angular has Formdata to deal with Multipart/formdata.

Change your saveAvailableCourse() function that is triggered after form submission to this:

saveAvailableCourse() {    const formData = new FormData();    formData.append('image', this.availableCourseForm.get('image').value);    // ---- add other data as key value pair on form data here ----    // sending request to server with formdata as payload    this.httpClient.post<any>(SERVER_URL, formData).subscribe(      (res) => console.log(res),      (err) => console.log(err)    );}