当前位置:网站首页>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)
边栏推荐
- The road of ospo construction of Weibo: how to promote enterprise open source through ospo construction?
- To avoid letting the transformation enterprises go astray, it is time to re understand the integration of xiahu warehouse| Q recommendation
- Four methods of finding combinatorial numbers
- 求组合数四种方法
- [tcapulusdb knowledge base] tcapulusdb operation and maintenance doc introduction
- 元宇宙土地:是什么让数字房地产变得有价值
- 【TcaplusDB知识库】TcaplusDB Tmonitor模块架构介绍
- 《气候韧性和可持续性》| 新研究表明超级飓风未来几年会对南亚产生更大破坏
- 【TcaplusDB知识库】TcaplusDB单据受理-创建游戏区介绍
- MFC自定义button实现颜色控制
猜你喜欢

Based on vue+nest Js+mysql cross platform open source community operation management system

2021ccpc online competition list

ST表学习

Go zero microservice Practice Series (III. API definition and table structure design)

塔米狗知识|全面剖析国有企业并购含义及其作用

ue5 小知识点 random point in Bounding Boxf From Stream
![[tcapulusdb knowledge base] Introduction to tmonitor system upgrade](/img/d4/b1a2b217f80b532ed1640a948fcca6.png)
[tcapulusdb knowledge base] Introduction to tmonitor system upgrade

【TcaplusDB知识库】Tmonitor系统升级介绍

Pagoda add a website: PHP project

Navicat connection MySQL in Pagoda
随机推荐
【TcaplusDB知识库】TcaplusDB常规单据介绍
22. Class E power amplifier design of ads usage record (Part 2)
Inclusion exclusion principle (number divisible)
日志1111
VSCode 如何将已编辑好的文件中的 tab 键转换成空格键
[tcapulusdb knowledge base] Introduction to tmonitor background one click installation (I)
模型搭建过程1==MIIDock
Interval modification multiplication and addition (a good example of understanding lazy tags)
QT 窗体的show/exec、close/hide,调用close析构没有执行
(幼升小信息-03)批量模板制作 幼儿基本信息收集文件夹(包含PDF、Word、证件文件夹)
[ROS] moveit rviz seven DOF Manipulator Simulation
Chapter VII document management
【TcaplusDB知识库】TcaplusDB单据受理-建表审批介绍
Necessary for Architects: system capacity status checklist
手动加密 ESP 设备量产固件并烧录的流程
【sql语句基础】——查(select)(单表查询顺序补充)
17 pictures: read and understand the first domestic guide for mainframe security capacity building
[tcapulusdb knowledge base] tcapulusdb doc acceptance - table creation approval introduction
求组合数四种方法
Similarities and differences between commonAPI and AUTOSAR AP communication management