写入

 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
Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐