I am trying to display a base 64 encoded image in react and it is not displaying the image on the webpage, it only shows up with an outline. How would I go about displaying the image?
Spring Boot backend
public void addNewBlog(String title, String description, String body, String author, MultipartFile image) throws IOException {
String fileName = StringUtils.cleanPath(image.getOriginalFilename());
Blog blog = new Blog(title, "", description, body, author);
blog.setName(fileName);
if(fileName.contains(".."))
{
System.out.println("not a valid file");
}
try {
blog.setContent(Base64.getEncoder().encodeToString(image.getBytes()));
} catch (IOException e) {
e.printStackTrace();
}
blog.setSize(image.getSize());
blog.setUploadTime(new Date());
blogRepository.save(blog);
}
Image
<img src={`data:image/jpeg;base64,${blog.content}`} style={{width: 100, height: 100 }} />