I have developing an app using spring boot and react js as frontend and backend respectively.
I have a database that consists of "title, image, content" and when I fetch without the frontend, everything works perfectly – I see all the details including the picture that is saved as path.
But the image doesn’t display in react…
This is my image tag in react js
<img src ={'data:image/jpg;base64,${article.file}'}/>
I was expecting everything to display but it’s only the title and content that are displaying.
2
Answers
In the code you provided, you are trying to create an element with a src attribute containing a template literal. However, you have a syntax issue in your template literal. You should use backticks (`) to create a template literal string and ${} to interpolate the value of article.file correctly.
Below is the corrected version.
<img src={`data:image/jpg;base64,${article.file}`} alt="Article Image" />
The issue could be with how you are using template literals in your ‘img’ tag.
The string interpolation syntax with ${…} requires backticks instead of single or double quotes.
Try changing your code to use backticks: