Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. class GetFileHandler(tornado.web.RequestHandler):
  2. def get(self):
  3.  
  4. fileid = self.get_argument('fileid', "")
  5.  
  6. cur.execute("""SELECT filepath FROM files_table WHERE file_id = %s""", (fileid, ))
  7. m = cur.fetchall()
  8. y = m[0]
  9. x = y[0]
  10.  
  11. path = x + "/" + fileid + ".jpg"
  12.  
  13. try:
  14. with open(path, 'rb') as f:
  15. data = f.read()
  16. self.write(data)
  17. self.finish()
  18. if __name__ == "__main__":
  19. tornado.options.parse_command_line()
  20. app = tornado.web.Application(handlers=[(r"/getit", GetFileHandler)])
  21. http_server = tornado.httpserver.HTTPServer(app)
  22. http_server.listen(options.port)
  23. tornado.ioloop.IOLoop.instance().start()
  24.  
  25. try:
  26. with open(path, 'rb') as f:
  27. data = f.read()
  28. self.write(data)
  29. self.finish()
  30. except IOError:
  31. print "Failed!!"
  32.  
  33. except IOError as xcpt:
  34. # IO error handling
  35. raise xcpt # if you want to propagate the exception
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement