Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class GetFileHandler(tornado.web.RequestHandler):
- def get(self):
- fileid = self.get_argument('fileid', "")
- cur.execute("""SELECT filepath FROM files_table WHERE file_id = %s""", (fileid, ))
- m = cur.fetchall()
- y = m[0]
- x = y[0]
- path = x + "/" + fileid + ".jpg"
- try:
- with open(path, 'rb') as f:
- data = f.read()
- self.write(data)
- self.finish()
- if __name__ == "__main__":
- tornado.options.parse_command_line()
- app = tornado.web.Application(handlers=[(r"/getit", GetFileHandler)])
- http_server = tornado.httpserver.HTTPServer(app)
- http_server.listen(options.port)
- tornado.ioloop.IOLoop.instance().start()
- try:
- with open(path, 'rb') as f:
- data = f.read()
- self.write(data)
- self.finish()
- except IOError:
- print "Failed!!"
- except IOError as xcpt:
- # IO error handling
- raise xcpt # if you want to propagate the exception
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement