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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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'])