Created
January 20, 2010 02:18
-
-
Save paxan/281530 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python | |
import paste.httpserver | |
form = """\ | |
<html> | |
<body> | |
<form method="post" enctype="multipart/form-data" action="/"> | |
<input type="file" name="photopicker" /> | |
<input type="submit" /> | |
</form> | |
</body> | |
</html> | |
""" | |
limit = 4 * 1024 * 1024 | |
def upload_app(environ, start_response): | |
if environ['REQUEST_METHOD'] == 'POST': | |
if int(environ.get('CONTENT_LENGTH', '0')) > limit: | |
start_response('400 Ouch', [('content-type', 'text/plain')]) | |
return ["Upload is too big!"] | |
# elided: consume the file appropriately | |
start_response('200 OK', [('content-type', 'text/html')]) | |
return [form] | |
paste.httpserver.serve(upload_app, port=7007) |
This file contains 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
#!/usr/bin/env python | |
import wsgiref.simple_server | |
form = """\ | |
<html> | |
<body> | |
<form method="post" enctype="multipart/form-data" action="/"> | |
<input type="file" name="photopicker" /> | |
<input type="submit" /> | |
</form> | |
</body> | |
</html> | |
""" | |
limit = 4 * 1024 * 1024 | |
def upload_app(environ, start_response): | |
if environ['REQUEST_METHOD'] == 'POST': | |
if int(environ.get('CONTENT_LENGTH', '0')) > limit: | |
start_response('400 Ouch', [('content-type', 'text/plain')]) | |
return ["Upload is too big!"] | |
# elided: consume the file appropriately | |
start_response('200 OK', [('content-type', 'text/html')]) | |
return [form] | |
httpd = wsgiref.simple_server.make_server('', 7007, upload_app) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment