Home > Blockchain >  React doesn't display images uploaded with Multer
React doesn't display images uploaded with Multer

Time:12-30

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

CodePudding user response:

This line should probably solve it:

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

CodePudding user response:

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