将文件流式传输到Pylons中的HTTP响应

将文件流式传输到Pylons中的HTTP响应,第1张

将文件流式传输到Pylons中的HTTP响应

FileApp
感谢 Chris AtLeeTHC4k
(来自此答案),我终于可以在班上使用它了。这种方法还允许我设置Content-
Length标头,而Pylons则遇到了很多麻烦,这使浏览器可以显示剩余时间的估算值。

这是完整的代码:

def _send_file_response(self, filepath):    user_filename = '_'.join(filepath.split('/')[-2:])    file_size = os.path.getsize(filepath)    headers = [('Content-Disposition', 'attachment; filename="' + user_filename + '"'),    ('Content-Type', 'text/plain'),    ('Content-Length', str(file_size))]    from paste.fileapp import FileApp    fapp = FileApp(filepath, headers=headers)    return fapp(request.environ, self.start_response)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/5649132.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存