Created
May 1, 2013 23:40
-
-
Save amjith/5499230 to your computer and use it in GitHub Desktop.
Example Tornado
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
import tornado.ioloop | |
import tornado.web | |
import os | |
HERE = os.path.dirname(__file__) | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
#self.render(HERE+'fileuploadform.html') | |
self.render('/Users/amjith/playground/python/tornado/async_api/fileuploadform.html') | |
def post(self): | |
fileinfo = self.request.files['filearg'][0] | |
fname = fileinfo['filename'] | |
#self.set_header('Content-Type', 'text/plain') | |
with open('uploads/' +fname, 'w') as f: | |
f.write(fileinfo['body']) | |
self.finish(fname) | |
#self.write(fileinfo['body']) | |
app = tornado.web.Application([ | |
(r'/', MainHandler), | |
], debug=True) | |
if __name__ == '__main__': | |
app.listen(8000) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment