Python: Cherry Py возвращает ZIP-файл.Как вернуть zip-файл в виде cherrypy при загрузке - PullRequest
0 голосов
/ 28 февраля 2019

Вот мой пример кода: проблема в том, что он возвращает загружаемый zip-файл, но файл поврежден / имеет ошибку.Я проверил файл, открыв его вручную в папке, и он работает.Я думаю, что проблема здесь заключается в передаче zip-файла из серверной части в cherrypy.Или как мне преобразовать zip-файл в тип файла?

cherrypy.response.headers['Content-Type'] = "'Content-Type', 'application/zip'"
cherrypy.response.headers['Content-Disposition'] = ('attachment; filename=' + 
    name.format(fname=name))
export_file = str(response["message_data"]["file"])

return export_file

Создание ZIP-файла

zipf = zipfile.ZipFile(full_directory + '.zip', 'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(full_directory + '/'):
    for file in files:
        zipf.write(os.path.join(root, file), arcname=file)
zipf.close()

file_upload = open(full_directory + '.zip', "r")

Передача ZIP-файла в CherryPy:

response_json["message_data"]["file"] = file_upload
response_json["message_data"]["name"] = file_name
...