0

Query images from database and render on html page

Hi! I am looking for the solution how to render images from database (BLOB) without saving the bytes after encode them to a folder in the app. Currently I iterate through the image columns and save each images into a folder with names [image_1.png,image_2.png] so every iteration increases the number while write the images. Is that possible to render images directly from db to a web page? It is like a blog, the rows have title, markdown, image, and created date. All columns are coming from a html form save to db and wish to render in a asyncronous website. Thank you for your help

12th Aug 2020, 6:17 AM
_] | [\]
_] | [\] - avatar
1 Odpowiedź
+ 2
Maybe write out the binary as follows? @app.route('/img/<int:id>.jpg') def get_image(id): bin=getbin(id)#function to get blob res=make_response(bin) res.headers.set('Content-Type', 'image/jpeg') res.headers.set( 'Content-Disposition', 'attachment', filename='%s.jpg' % id) return res Also play with res.cache_control.max_age to avoid overloading the server with image requests if necessary, and add some extra functionality to handle the different mime types based on file extension as stored in the db Just for reference: https://pynative.com/JUMP_LINK__&&__python__&&__JUMP_LINK-sqlite-blob-insert-and-retrieve-digital-data/
12th Aug 2020, 10:51 AM
Ockert van Schalkwyk
Ockert van Schalkwyk - avatar