扫码关注官方订阅号
小弟初学Tornado,卡在这几天了,请大家解惑。 如题,就是想实现访问一个URL,返回一张图片。类似Flask中send_file的功能 感觉很简单但是一直没找到解决方法...
认证高级PHP讲师
可以看下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() #...
虽然没用过,但是应该就是在response的stream中把文件流写入,之前设置好content-type就行了
静态文件还是Nginx吧,Tornado返回流数据会阻塞线程吧,Tornado是单进程单线程模型,返回图片什么的还是感觉不靠谱
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
可以看下web.py 中的代码的
虽然没用过,但是应该就是在response的stream中把文件流写入,之前设置好content-type就行了
静态文件还是Nginx吧,Tornado返回流数据会阻塞线程吧,Tornado是单进程单线程模型,返回图片什么的还是感觉不靠谱