Skip to content

Instantly share code, notes, and snippets.

@eguven
Created September 28, 2012 17:29
Show Gist options
  • Save eguven/3801145 to your computer and use it in GitHub Desktop.
Save eguven/3801145 to your computer and use it in GitHub Desktop.
motor.DataServer suggestion
# 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