0

I need to show an image that I uploaded in the node server, I can access the image in the server because I put the file public but I dont know how can import the image in react because when I try to import in a usual way like

<img src={process.env.PUBLIC_URL + "../../../../../api/uploads/1570230561283padre-e-hija.jpg"} style={imgStyle}/>

the response from the server is 404 not found. So how can I fix this?

Thanks :)

1
  • You're probably going to want to look into serving this image file (or images) statically with the built in methods from Express. <expressjs.com/en/starter/static-files.html> Commented Dec 5, 2019 at 16:16

1 Answer 1

1

It's better to use express.static function to serve static content

//in nodejs

    app.use(express.static('pathToUploadFolder'))

//react js

    <img src="/1570230561283padre-e-hija.jpg" style={imgStyle}/>
Sign up to request clarification or add additional context in comments.

1 Comment

can u paste out code snippet and image of folder structure?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.