python - Bottle web 框架:如何将 csv 文件返回给 Angular 客户端
问题描述
在瓶子网络框架中,我需要返回一个 csv 文件以从 Angular 客户端下载。
@route('/project/download')
def download_projects_result_file():
#here i have a csv file in /tmp/proj_category.csv
return ....?
如何将 csv 文件返回给客户端?
谢谢
解决方案
你想在客户端加载文件的内容还是直接下载?
要直接下载,Content-Disposition
请在瓶子响应中使用标头。
这是一个例子:
from bottle import LocalResponse, route
@route('/project/download')
def download_projects_result_file():
with open('/tmp/proj_category.csv') as file:
file.seek(0)
byte_data = file.read()
response = LocalResponse(
body=byte_data,
headers={
"Content-Disposition": "attachment; filename='filename.csv'",
"Content-Type": "text/csv",
}
)
return response
推荐阅读
- node.js - Node Express 服务器返回“FALSE”
- android - 能够将振动转发到手表的颤振振动包?
- python - 在 S3 存储桶中查找最新文件
- c# - LINQ 上的 IEnumerable.Except() 不在理想的源列表和目标列表之间运行
- c# - 无法从 'char[]' 转换为 'string[]'
- c++ - 传递双指针和指针作为参数的区别
- tcl - 我可以自动计算 tcl 中某些数据的移动平均值吗?
- reactjs - Git 日志只显示最后一次提交
- java - 如何在 java/android 中获得完美的 UTC 时间?
- android - OnCallEvents 在 android 中的两个对等点的套接字中不起作用