Yes I know it's a bad idea/bad practice to save images in a database, nevertheless I have to as those are the requirements of my professor which is why I have to achieve it anyways.
The setup:
I have a user table with an img column of type bytea
where I want to store the image blob and later retrieve them through fetch and display them on my html template as base64.
onFileSelect I save the uploaded image to a variable which gets saved to the database with a fetch put request. This works so far and looks like this:
function onFileSelect(event) {
img_upload = event.target.files[0];
console.log(img_upload);
}
When I retrieve the data from the database I get back a bytearray which I can convert back from bytearray to a string. I also get the same result back as it's stored in the database:
But shouldn't it look more like this? How do I convert it to such a data URL so I can add it to my img :src?
img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4 //8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
I tried all day to get this to work and I have no clue where my mistake lies with all this image conversion.. I've had to do a similar thing with MySQL Blob types once but that wasn't even remotely as difficult as this bytea stuff to figure out Your help would be appreciated