I need to save an image file into sqlite database in python. I could not find a solution. How can I do it?
Thanks in advance.
write - cursor.execute('insert into File
(id, name, bin) values (?,?,?)', (id, name, sqlite3.Binary(file.read())))
read - file = cursor.execute('select bin from File where id=?', (id,)).fetchone()
if you need to return bin data in web app - return cStringIO.StringIO(file['bin'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With