Closed kgdunn closed 13 years ago
Create ZIP file in a staging area; don't recreate unless the submission is updated
Download a zip file: http://bitkickers.blogspot.com/2010/07/django-zip-files-create-dynamic-in.html
from StringIO import StringIO
from zipfile import ZipFile
from django.http import HttpResponse
def download(request, company_id):
in_memory = StringIO()
zip = ZipFile(in_memory, "a")
zip.writestr("file1.txt", "some text contents")
zip.writestr("file2.csv", "csv,data,here")
# fix for Linux zip files read in Windows
for file in zip.filelist:
file.create_system = 0
zip.close()
response = HttpResponse(mimetype="application/zip")
response["Content-Disposition"] = "attachment; filename=two_files.zip"
in_memory.seek(0)
response.write(in_memory.read())
return response
Fixed, in various commits on and before 10 August
Provides a ZIP file of code.
Add "http://" at the top of snippet downloads