Created
January 18, 2016 10:44
-
-
Save dmitru/05b7efb94fd23637a451 to your computer and use it in GitHub Desktop.
How to create and file_send() in-memory zipfiles in Flask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
memory_file = BytesIO() | |
with zipfile.ZipFile(memory_file, 'w') as zf: | |
files = result['files'] | |
for individualFile in files: | |
data = zipfile.ZipInfo(individualFile['fileName']) | |
data.date_time = time.localtime(time.time())[:6] | |
data.compress_type = zipfile.ZIP_DEFLATED | |
zf.writestr(data, individualFile['fileData']) | |
memory_file.seek(0) | |
return send_file(memory_file, attachment_filename='capsule.zip', as_attachment=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment