In a certain GET request, I need to read a file locally, depending on parameters in the request, and send it on request’s input stream. How do I do it?
class GetArchives(tornado.web.RequestHandler):
def get(self, param1, param2):
path = calculate_path(param1, param2)
try:
f = open(path, 'rb')
# TODO: send this file to request's input stream.
except IOError:
raise tornado.web.HTTPError(404, 'Invalid archive')
Try this(not for big file):
There is
StaticFileHandlerin tornado, see tornado doc