Created
January 2, 2018 11:36
-
-
Save hsleonis/1ea5bd50e03db8c4c20c2a462028ad42 to your computer and use it in GitHub Desktop.
Create zip file
This file contains hidden or 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
def home(request): | |
inMemoryOutputFile = BytesIO() | |
# zipFile = ZipFile(inMemoryOutputFile, 'w') | |
# zipFile.writestr('OEBPS/content.xhtml', 'hello world') | |
# zipFile.close() | |
zipfile = ZipFile(inMemoryOutputFile, "w") | |
zipfile.writestr("AB/stuff.txt","1sdfghj") | |
zipfile.writestr("AB/two.txt","2sdfghj") | |
zipfile.writestr("AB/hello.txt","3sdfgh") | |
zipfile.close() | |
inMemoryOutputFile.seek(0) | |
response = HttpResponse ( zipfile ) | |
response['Content-Disposition'] = "attachment; filename=%s" % "test.zip" | |
return response | |
zz = zipfile.ZipFile('Backup.zip', 'w' , zipfile.ZIP_DEFLATED) | |
zinfo = zipfile.ZipInfo('file_name.txt', time.localtime()[:6]) | |
zinfo.compress_type = zipfile.ZIP_DEFLATED | |
zz.writestr(zinfo, file_content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment