我正在尝试从数据库中获取文件并将其写入磁盘。该文件存储为 BLOB。
现在我有以下代码:
#!/usr/bin/python
import MySQLdb
db2 = MySQLdb.connect(host="localhost",
user="root",
passwd="root",
db="digit")
cur = db2.cursor()
#get the name of the file
cur.execute("SELECT Name FROM ContentFiles WHERE ID=3")
nombre = cur.fetchone()
#open file and write into.
with open(nombre[0],"wb") as output_file:
cur.execute("SELECT File FROM ContentFiles WHERE ID=3")
ablob = cur.fetchone()
output_file.write(ablob[0])
任何帮助,将不胜感激。谢谢 :)
我调试并获取文件并将其写入磁盘,但是当我打开它时显示错误消息:
Not a JPEG file: starts with 0x2f 0x39