-
-
Save hivefans/8121344 to your computer and use it in GitHub Desktop.
|-|{"files":{"tornadofileupload.py":{"env":"plain"}},"tag":"bigdata"}
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 | |
import tornado.ioloop | |
import tornado.web | |
import os, uuid | |
__UPLOADS__ = "uploads/" | |
class Userform(tornado.web.RequestHandler): | |
def get(self): | |
self.render("fileuploadform.html") | |
class Upload(tornado.web.RequestHandler): | |
def post(self): | |
fileinfo = self.request.files['filearg'][0] | |
print "fileinfo is", fileinfo | |
fname = fileinfo['filename'] | |
extn = os.path.splitext(fname)[1] | |
cname = str(uuid.uuid4()) + extn | |
fh = open(__UPLOADS__ + cname, 'w') | |
fh.write(fileinfo['body']) | |
self.finish(cname + " is uploaded!! Check %s folder" %__UPLOADS__) | |
application = tornado.web.Application([ | |
(r"/", Userform), | |
(r"/upload", Upload), | |
], debug=True) | |
if __name__ == "__main__": | |
application.listen(8888) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment