I want to save an encoded image in to a Postgres database using the @Lob annotation in Spring. There are no errors when I test the application, I browse an image and then save it. But when I open the database instead of the base64 encoded image in the image column I just have a couple of numbers (41417, 41418 and so on).
Here is a part of the code from my class.
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
private String name;
@Lob
private String imageBase64;
Here is the function I use to save the object in to the database.
public Product saveProduct(Product product, MultipartFile image) throws IOException {
if (image != null && !image.getName().isEmpty()) {
byte[] bytes = image.getBytes();
String base64Image = String.format("data:%s;base64,%s", image.getContentType(), Base64.getEncoder().encodeToString(bytes));
product.setImageBase64(base64Image);
}
return this.productRepository.save(product);
}
But when it saves it in to the database it looks like this (column image_base64).
