so i am creating a web app that allows users to post images and i save the images as binary using multer into my mongo database, now i want to retrieve the images and render it on the webpage but the images dont show when i use the img tag, please do you know how i can transform binary image data to normal webpage readable image format, just found out i cant use "fileSystem" in react and i was wondering if there is anyway i could do this or any snippet of code i could use to complete this task, thanks!
2 Answers
If you can't/don't want to store it as a regular file and serve it, you could try displaying it using base64 format. You can find more about it here: How to display Base64 images in HTML?
But in simple words, you simply have to display a tag like this <img src="data:image/png;base64,base 64 here ..." />
But I strongly suggest that you should use some file upload functionality instead of saving the raw bytes to the database.
<img src="DATA GOES HERE">. See stackoverflow.com/questions/8499633/…