pysqlite - 如何保存图像

Mus*_*gin 7 python sqlite blob image pysqlite

我需要在python中将图像文件保存到sqlite数据库中.我找不到解决方案.我该怎么做?

提前致谢.

naz*_*zca 9

-cursor.execute('insert into File (id, name, bin) values (?,?,?)', (id, name, sqlite3.Binary(file.read())))

阅读 -file = cursor.execute('select bin from File where id=?', (id,)).fetchone()

如果您需要在Web应用程序中返回bin数据 - return cStringIO.StringIO(file['bin'])