要使代码适用于您提供的链接,您需要在下面的代码中添加我的评论后的行...
def upload(self, myFile):
MySQLconnection = MySQLdb.connect(host=cherrypy.request.app.config['Database']['host'],
passwd=cherrypy.request.app.config['Database']['passwd'],
db=cherrypy.request.app.config['Database']['db'],
user=cherrypy.request.app.config['Database']['user'],
port=cherrypy.request.app.config['Database']['port'],
cursorclass=DictCursor)
MySQLcursor = MySQLconnection.cursor()
size = 0
# add this line
all_data = bytearray()
while True:
data = myFile.file.read(8192)
all_data += data
if not data:
break
size += len(data)
saved_file=open('upload_path', 'wb')
saved_file.write(all_data)
saved_file.close()
MySQLcursor.execute("insert into ImagePathDatabase (path) values ('" + MySQLdb.escape_string(myFile.filename) + "')")
MySQLcursor.execute("commit;")
如果您需要更多帮助,请告诉我。
安德鲁