Created
September 26, 2012 06:20
-
-
Save kazup0n/3786409 to your computer and use it in GitHub Desktop.
zip file download in python
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 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