在某个GET
请求中,我需要根据请求中的参数在本地读取一个文件,并根据请求的输入流发送它。我该怎么做?
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')
以下是一个适用于任意大小文件的解决方案:
尝试此操作(不适用于大文件):
龙卷风中有
StaticFileHandler
,见tornado doc相关问题 更多 >
编程相关推荐