Last active
August 29, 2015 14:21
-
-
Save anishmenon/2b3b0091a790c599cab2 to your computer and use it in GitHub Desktop.
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An error occurred while loading the archive