I want to store my jpg images in my sql database and then display those images on my flask website. I tried doing it by converting the image to binary and storing it in BLOB datatype in sql but I cannot understand how to convert that binary to image in html and display that image on my flask webpage.
Asked
Active
Viewed 43 times
0
-
Why would you want to store an image in a database where it takes lots of space and you can't see it and it makes your backup enormous? Wouldn't it be better to store it in your filesystem where you can see it and just store its filename in your database? – Mark Setchell Jul 13 '23 at 21:04
-
You probably need to convert it to base64 and back, but this question doesn't have enough detail to determine what you are trying to do here. – Pete Jul 13 '23 at 21:15
-
Does this answer your question? [Flask to return image stored in database](https://stackoverflow.com/questions/11017466/flask-to-return-image-stored-in-database) – Marat Jul 13 '23 at 21:23
-
Generally you don't - you store the image somewhere and then you store the image _metadata_ in your db, including the location where that image can be found (static asset dir, S3 URL, etc) so that you can template that location into your page responses and not have to worry about transmitting/rehydrating/rehosting huge amounts of data every single database call. – Mike 'Pomax' Kamermans Jul 13 '23 at 21:27
-
@pete NO. sql databases can store blobs just fine. never ever suggest base64 for any reason. – Christoph Rackwitz Jul 15 '23 at 11:42
-
What do you have against base64? Bloats the blob? I think the JS side img src is going to want that format, but could be converted later. – Pete Jul 17 '23 at 16:34