makar0v
makar0v

Reputation: 192

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')))

Upvotes: 2

Views: 1249

Answers (2)

eol
eol

Reputation: 24555

You need to actually serve the images that reside in your uploads folder. One way to do this is to use the express static middleware. Assuming your uploads folder resides in your app's root, you'd simply add to your express app:

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

Upvotes: 1

Mohammad Taheri
Mohammad Taheri

Reputation: 464

This line should probably solve it:

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

Upvotes: 2

Related Questions