Thymeleaf / Loading image from DTO

Hello guys, I'm trying to make a profile manager for any user that is successfully identified, I can render every user datas in my template except for my image, in my inspector it says the image can't load The image comes from my DTO and it's persisted in my database and I have implemented my getters and setters properly but I still don't know why it doesn't work. In my browser it obviously shows Image de profil Here's my code in my template :
<h1 th:if="${user != null}">Profil de <span th:text="${user.firstName}"></span></h1>
<h1 th:if="${user != null}">Profil de <span th:text="${user.lastName}"></span></h1>
<h1 th:if="${user != null}">Profil de <span th:text="${user.email}"></span></h1>

<div th:if="${user != null}">
<img th:src="${user.image}" alt="Image de profil" width="400px"/>
</div>

<h1 th:if="${user == null}">Profil de <span th:text="${error}">User not found !!!</span></h1>
<h1 th:if="${user != null}">Profil de <span th:text="${user.firstName}"></span></h1>
<h1 th:if="${user != null}">Profil de <span th:text="${user.lastName}"></span></h1>
<h1 th:if="${user != null}">Profil de <span th:text="${user.email}"></span></h1>

<div th:if="${user != null}">
<img th:src="${user.image}" alt="Image de profil" width="400px"/>
</div>

<h1 th:if="${user == null}">Profil de <span th:text="${error}">User not found !!!</span></h1>
14 Replies
JavaBot
JavaBot4mo ago
This post has been reserved for your question.
Hey @NoSung! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Peter Rader
Peter Rader4mo ago
Show the DTO user please.
Sung
SungOP4mo ago
@NotEmpty(message = "This field cannot be empty")
private String image;

/**
* @return String return the image
*/
public String getImage() {
return image;
}

/**
* @param image the image to set
*/
public void setImage(String image) {
this.image = image;
}
@NotEmpty(message = "This field cannot be empty")
private String image;

/**
* @return String return the image
*/
public String getImage() {
return image;
}

/**
* @param image the image to set
*/
public void setImage(String image) {
this.image = image;
}
Peter Rader
Peter Rader4mo ago
Can you give an example what is inside the image-string?
Sung
SungOP4mo ago
This is a simple image in jpg persisted in my db
Peter Rader
Peter Rader4mo ago
You mean the raw bytes of the image as an string?
Sung
SungOP4mo ago
I don't know what you mean by raw bytes, but yes I typed it in string. I wasn't supposed to do it this way ? also I'm trying to learn thymeleaf and I'm new to Spring Boot so maybe there's some notions I misunderstood
Peter Rader
Peter Rader4mo ago
Sorry, you need to give an exact example of one image-string.
Sung
SungOP4mo ago
You mean from my db ?
Peter Rader
Peter Rader4mo ago
Yes
Sung
SungOP4mo ago
I have one image called jiri.jpg and that's it no other images
JavaBot
JavaBot4mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Sung
SungOP4mo ago
@Peter Rader I changed my image type in my entities and DTO to bytes, people recommended me to do that but with the code I have in my template and how I have this image, this shouldn't be an issue to display it I ask chatGPT and it says I don't need an URL if this comes from my db
<div th:if="${user != null}">
<img th:src="${user.image}" alt="Image de profil" width="400px"/>
</div>
<div th:if="${user != null}">
<img th:src="${user.image}" alt="Image de profil" width="400px"/>
</div>
JavaBot
JavaBot4mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server