It seems that my Google-fu has failed me since I can't find similiar problems or solutions. I want to show users image in the users profile page, but the image eather does not load or just consumes everything else.
The profile picture is save as such:
@Lob
@Basic(fetch = FetchType.EAGER)
private byte[] profilePicture;
This the controlle which should return the image. The HttpServeltResponse is something I found related to this, but I made the image consume the whole page.
@GetMapping("/profile")
public String showporfile(Model model, Principal principal, HttpServletResponse response) throws IOException {
acc = accountRepo.findByUsername(principal.getName());
model.addAttribute("accountName", acc.getName());
model.addAttribute("skills", acc.getSkills());
model.addAttribute("accounts", acc);
/*response.setContentType("image/jpg");
InputStream is = new ByteArrayInputStream(acc.getProfilePicture());
IOUtils.copy(is, response.getOutputStream());*/
return "profile";
}
And this is my HTML in which I have tried to get the picture to show. At the moment I get error stating: The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). It seems that the image is now going as: http://localhost:8080/[B@1c535b01 and I don't know why that is.
<div th:each="account : ${accounts}">
<label th:text="${account.name}"></label>
<div class="header_image clearfix">
<img th:src="${account.profilePicture}"/>
</div>
</div>
Thank you for advance I have been stuck with this for 3 days now.
EDIT the image is stored to h2 database and linked to user as seen up.