现在我使用此代码在没有 ajax 的情况下上传
@cherrypy.expose
def upload(self, file):
uload_path = pm.get_package_download_dir()
file_name = 'some.file'
if not isdir(uload_path):
try:
makedirs(uload_path)
except ValueError:
raise cherrypy.HTTPError(400, 'SOME_ERROR')
uload_path = uload_path + os.path.sep + file_name
size = 0
all_data = ''
while True:
data = file.file.read(8192)
all_data += data
if not data:
break
size += len(data)
try:
saved_file=open(uload_path, 'wb')
saved_file.write(all_data)
saved_file.close()
except ValueError:
raise cherrypy.HTTPError(400, 'SOME ERROR')
print 'OK'
但我找不到任何使用 Cherrypy 和 Jquery 上传 ajax 文件的示例。请帮忙!