Skip to content

Instantly share code, notes, and snippets.

@amjith
Created May 1, 2013 23:40
Show Gist options
  • Save amjith/5499230 to your computer and use it in GitHub Desktop.
Save amjith/5499230 to your computer and use it in GitHub Desktop.
Example Tornado
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