Multer File Upload Issue: ENOENT Error When Trying to Store Files in Public/Temp Folder

Description:

I’m currently working on the backend of my project, utilizing Multer to handle image file uploads from the frontend. For the frontend, I’m using Postman as a testing tool.

Here’s a brief overview of the algorithm I’m developing for user registration:

  1. Users submit image files from the frontend.
  2. These files are temporarily stored in the project/temp folder, located in the root directory.
  3. Subsequently, the files are to be uploaded to Cloudinary.

You can find the full algorithm in the source code on my GitHub repository [https://github.com/mangesh123vispute/SocialMediaPro].

Problem:

While attempting to store files in the public/temp folder using Multer, I encounter the following error:

plaintext
Error: ENOENT: no such file or directory, open ‘C:UserslaxmaOneDriveDesktopcodinglearningbackendprojectpublictempmangesh.jpg’

Screenshots:

Postman Request:
Postman Request

Postman Error:
Postman Error

Issue Description:

I believe the problem lies within the multer.middleware.js file rather than the user.controllers.js. Here’s my reasoning:

  1. I added a console.log("req.body: ", req.body); statement inside the user.controller.js file.
  2. However, this log statement is not being printed, indicating that the registerUser controller is not being called.
  3. Therefore, I infer that the error is likely in the middleware (multer.middleware.js).
  4. Additionally, the files (images) are not being stored in the public/temp folder as expected.

user.controllers.js:Added console.log() to check it is executing or not.
enter image description here

multer.middelware.js
enter image description here

user.routes.js
enter image description here

Error with console logs:
enter image description here

Question:

Can someone help me identify and resolve the issue in the multer.middleware.js file that might be preventing the registerUser controller from being called and causing the files not to be stored in the designated folder?