Skip to content

Instantly share code, notes, and snippets.

@dmitru
Created January 18, 2016 10:44
Show Gist options
  • Save dmitru/05b7efb94fd23637a451 to your computer and use it in GitHub Desktop.
Save dmitru/05b7efb94fd23637a451 to your computer and use it in GitHub Desktop.
How to create and file_send() in-memory zipfiles in Flask
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