python使用sqlite3写入、读取图片
写入with open('test.jpg', 'rb') as f:content = base64.b64encode(f.read())sql = f"INSERT INTO street (tileZ,tileX,tileY,image) VALUES (?,?,?,?);"print(sql)cursor.execute(sql, (z, x, y, sqlite3.Binary(con
·
写入
with open('test.jpg', 'rb') as f:
content = base64.b64encode(f.read())
sql = f"INSERT INTO street (tileZ,tileX,tileY,image) VALUES (?,?,?,?);"
print(sql)
cursor.execute(sql, (z, x, y, sqlite3.Binary(content)))
con.commit()
读取
cursor = con.cursor()
sql = f"SELECT image FROM street WHERE tileX={x} AND tileY={y} AND tileZ={z}"
cursor.execute(sql)
value = cursor.fetchone()
if value:
tile_content = value[0]
tile_content = b64decode(tile_content)
con.close()
response = make_response(b64decode(tile_content))
response.headers['Content-Type'] = 'image/jpeg'
return response
更多推荐




所有评论(0)