Skip to content

Instantly share code, notes, and snippets.

@anishmenon
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anishmenon/2b3b0091a790c599cab2 to your computer and use it in GitHub Desktop.
Save anishmenon/2b3b0091a790c599cab2 to your computer and use it in GitHub Desktop.
import os
import zipfile
import StringIO
from django.http import HttpResponse
def getfiles(request):
filenames = ["/home/node4/anish/varnan/1.jpg", "/home/node4/anish/varnan/2.jpg"]
zip_subdir = "somefiles"
zip_filename = "%s.zip" % zip_subdir
s = StringIO.StringIO()
zf = zipfile.ZipFile(s, "w")
for fpath in filenames:
fdir, fname = os.path.split(fpath)
zip_path = os.path.join(zip_subdir, fname)
zf.write(fpath, zip_path)
print zf
zf.close()
resp = HttpResponse(s.getvalue(), mimetype = "application/x-zip-compressed")
resp['Content-Disposition'] = 'attachment; filename=%s' % zip_filename
return resp
@Varnan
Copy link

Varnan commented May 19, 2015

An error occurred while loading the archive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment