0

Just to inform that backend is in NodeJS and frontend in ReactJS. [enter image description here][1] [1]: https://i.stack.imgur.com/ifklU.png

I have added how my structure of project look like in image. When client save image/file it saves under backend in folder named uploadedData. Consider that I already know the name of photo and of course directory also. Can someone explain me how can I get image from uploadedData directory from backend and show on frontend with the help of components/Products.js which is part of frontend. Since I am newbie it would be good if I get little detailed answer. Note: I have achieved this thing with really poor approach: Writing this line of code app.use('/uploadedData', express.static(__dirname + '/uploadedData')) allow me to see image directly on the browser at http://localhost:8081/uploadedData/artikles/1222222.jpg and if I write the same url equal to src in the <img> tag I have achieved the goal but I want to get better approach.

Shakeel
  • 21
  • 7
  • What's wrong with the approach you mentioned? I mean, you might want to tweak it a little (like, do you need to have some kind of access control?), but having your web server use its regular file-serving logic to deliver the image from the directory seems like a reasonable approach. I've written this myself. – Willis Blackburn Feb 19 '21 at 23:19
  • Does this answer your question? [Node Express sending image files as API response](https://stackoverflow.com/questions/17515699/node-express-sending-image-files-as-api-response) – wurde Feb 20 '21 at 01:27

0 Answers0