- 我正在使用 python 将测试数据加载到我的 SQL Server 数据库中,并且能够成功获取图像并将它们分解为字节并将它们存储在数据库中,但是当尝试取回字节并将其解码以将其保存为一种新的文件类型,我得到的只是一个空白图像文件。不知道我在这里做错了什么......
- 我已经尝试使用其他教程和类似问题中的 base64 进行多次迭代,但似乎找不到可以解决我的问题的方法。
SQLCommand = ("SELECT Photo FROM Validation")
cursor.execute(SQLCommand)
data = cursor.fetchone()[0]
image_64_decode = base64.decodebytes(data)
image_result = open('booking.png', 'wb')
image_result.write(image_64_decode)
image_result.close()
connection.close()
The expected result is that I should be able to fetch the bytes from the database which the database column is varbinary(max) the equivalent of bytes in python. once the bytes are fetched using the script in python it should save a file as booking.png which should replicate the image i stored in the database.
When i run the script i don't get an error, and in fact it saves a file, but the file is empty containing 1kb and does not reproduce the image. Not sure where i am going wrong, but it seems like it's not properly fetching the bytes.