Created
September 28, 2012 17:29
-
-
Save eguven/3801145 to your computer and use it in GitHub Desktop.
motor.DataServer suggestion
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
# related parts of motor.DataServer suggestion | |
# something along the lines of... | |
class DataServer(object): | |
@tornado.gen.engine | |
def stream(self, handler, file_id): | |
fs = yield motor.Op(motor.MotorGridFS(db).open) | |
try: | |
gridout = yield motor.Op(fs.get, file_id) | |
except NoFile: | |
handler.send_error(404) | |
return gridout.stream(handler) # which sets headers | |
class FileServeHandler(tornado.web.RequestHandler): | |
@tornado.web.asynchronous | |
def get(self, file_id): | |
motor.DataServer().stream(self, file_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment