Search code examples
node.jsexpressmulter

React doesn't display images uploaded with Multer


After uploading an image with Multer to the uploads folder which is located in the root with server folder and client folder, React cannot access the images in the uploads folder, as the api/upload route returns just a string as /uploads/the_image_name.

I thought I should upload the images to the public folder in the React folder but I found that the convention is using an uploads folder in the root.

Server :

app.use('/uploads', express.static(path.join(__dirname, '/uploads')))

Solution

  • This line should probably solve it:

    app.use("/uploads", express.static('uploads'))