Skip to content

Instantly share code, notes, and snippets.

@kazup0n
Created September 26, 2012 06:20
Show Gist options
  • Select an option

  • Save kazup0n/3786409 to your computer and use it in GitHub Desktop.

Select an option

Save kazup0n/3786409 to your computer and use it in GitHub Desktop.
zip file download in python
def application(environ, start_response):
zip = 'foo.zip'
length = lengthof(zip)
buff = readzip(zip)
start_response('200 OK', [('Content-type', 'application/zip'), ('Content-Disposition', 'attachment; filename=' + zip), ('Content-Length',str(length))])
return buff
def readzip(file):
return open(file, 'rb').read()
def lengthof(file):
import os.path
return os.path.getsize(file)
from wsgiref import simple_server
if __name__ == '__main__':
server = simple_server.make_server('', 8080, application)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment