Skip to content
Advertisement

multer npm: TypeError: Cannot read property ‘path’ of undefined

I have a problem uploading an image file to my server, I watched a tutorial on YouTube about multer and I do exactly the same thing that is done in the tutorial and for whatever reason I get an error: (“TypeError: Cannot read property ‘path’ of undefined”). I googled for the error and found some people having the same issue and I tried to solve it like them, but it didn’t work for me.

This is my code:

JavaScript

the Image Schema and model:

JavaScript

My post route:

JavaScript

My html upload form:

JavaScript

and when I logged the value of (req.file) it says that its type is ‘undefined’, so that must mean that multer didn’t recognize or even didn’t received the image file. what am I doing wrong that multer doesn’t get the file?

Advertisement

Answer

I changed the destination to ./uploads works fine for me

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement