当前位置:网站首页>How fastapi responds to file downloads
How fastapi responds to file downloads
2022-06-13 11:33:00 【Mad devil coding King】
fastapi Want to respond to file download , Need from starlette.responses Import FileResponse
from starlette.responses import FileResponse
And before that, you have to install aiofiles Dependency package
pip install aiofiles
The complete code is as follows :
FileResponse The first parameter is the path of the file , The second parameter indicates the name of the file displayed when downloading
import uvicorn
from fastapi import FastAPI
from starlette.responses import FileResponse
app = FastAPI()
@app.get("/file")
def file():
return FileResponse('./demo.md', filename='demo.md')
if __name__ == '__main__':
uvicorn.run('main:app', port=5555, reload=True)
边栏推荐
- 【TcaplusDB知识库】TcaplusDB常规单据介绍
- Pyepics download and installation
- 【TcaplusDB知识库】Tmonitor后台一键安装介绍(二)
- [tcapulusdb knowledge base] tcapulusdb operation and maintenance doc introduction
- Web 3.0?高成本版的P2P而已
- 【TcaplusDB知识库】TcaplusDB单据受理-建表审批介绍
- Ubuntu installs MySQL compressed package for future reference
- Socket programming (medium)
- 阿里一季度员工减少4000人;程序员写脚本抢挂疫苗号,牟利40万被刑拘;搜狐遭遇史诗级邮件诈骗,张朝阳回应 | Q资讯
- Private computing fat core concepts and stand-alone deployment
猜你喜欢
关于 SAP Spartacus CmsService.getComponentData 可能的优化思路
我是如何解决码云图床失效问题?
Pagoda add a website: PHP project
Go needs to add an arrow syntax, which is more like PHP!
Audio and video technology development weekly 𞓜 249
【TcaplusDB知识库】TcaplusDB单据受理-创建业务介绍
Navicat connection MySQL in Pagoda
Vivo large scale kubernetes cluster automation operation and maintenance practice
[tcapulusdb knowledge base] Introduction to tcapulusdb general documents
领导说要明天上线,这货压根不知道开发流程
随机推荐
[tcapulusdb knowledge base] tcapulusdb doc acceptance - Introduction to creating game area
Inclusion exclusion principle (number divisible)
Performance monster on arm64: installation and performance test of API gateway Apache APIs IX on AWS graviton3
C#/VB.NET 在Word转PDF时生成目录书签
Type de condition pour ts Advanced
2021ccpc online competition list
Audio and video technology development weekly 𞓜 249
[tcapulusdb knowledge base] Introduction to tmonitor stand-alone installation guidelines (II)
Model building process 1==miidock
高斯消元求n元方程组
Environ. Sci. Technol. (if=9.028) | impact of urban greening on atmospheric environment
Chapter VI i/o management
MIIdock文件分布
Count the number of special subsequences (0, 1, 2) DP
Vivo large scale kubernetes cluster automation operation and maintenance practice
Socket programming (medium)
[tcapulusdb knowledge base] Introduction to tmonitor background one click installation (I)
模型搭建过程1==MIIDock
COM的模式变化引起的IPdu Handling【接收截止日期监控】
[tcapulusdb knowledge base] Introduction to new models of tcapulusdb