需要Tornado在response中返回图片求解决方法,,小弟初学Tornado,


小弟初学Tornado,卡在这几天了,请大家解惑。
如题,就是想实现访问一个URL,返回一张图片。类似Flask中send_file的功能
感觉很简单但是一直没找到解决方法...

虽然没用过,但是应该就是在response的stream中把文件流写入,之前设置好content-type就行了

静态文件还是Nginx吧,Tornado返回流数据会阻塞线程吧,Tornado是单进程单线程模型,返回图片什么的还是感觉不靠谱

可以看下web.py 中的代码的

class StaticFileHandler(RequestHandler):    @gen.coroutine    def get(self, path, include_body=True):        #...        if include_body:            content = self.get_content(self.absolute_path, start, end)            if isinstance(content, bytes_type):                content = [content]            for chunk in content:                self.write(chunk)                yield self.flush()        #...   

编橙之家文章,

评论关闭