当前位置:网站首页>19_请求表单与文件
19_请求表单与文件
2022-07-26 02:03:00 【空巢青年_rui】
19_请求表单与文件
我们可以同时使用File和Form定义文件和表单字段。
说明:接收上传文件或表单数据,要预装
python-multipart模块。
定义File 和 Form 参数
使用和之前的相同的方式同时创建File和Form参数:
from fastapi import FastAPI, File, Form, UploadFile
app = FastAPI()
@app.post("/files/")
async def create_file(
file: bytes = File(), fileb: UploadFile = File(), token: str = Form() # 同时定义File和Form参数
):
return {
"file_size": len(file),
"token": token,
"fileb_content_type": fileb.content_type,
}
文件和表单字段将被作为表单数据由用户上传,然后我们在后端路径操作函数中接收。
同时,我们也可以将部分文件声明为bytes,另一部分声明为UploadFiles。
警告:
我们可以在一个路径操作中声明多个
File和Form参数,但是,不能同时声明要接收JSON的Body字段。因为此时请求体的编码为
multipart/form-data, 而不是application/json。这是HTTP协议的规定,不是FastAPI的问题。
边栏推荐
- 1. Mx6ul core module use serial RTC test (XII)
- G. Count the trains (thought set + two points)
- 1. Mx6ul core module serial Ethernet test (VII)
- Digital transformation behind the reshaping growth of catering chain stores
- How idea can quickly delete recently opened projects
- 1. Mx6ul core module use serial -rs485 test (x)
- 重发布基础与配置
- Common shell operations in Phoenix
- AttributeError: ‘Document‘ object has no attribute ‘pageCount‘
- Move bricks (greedy perturbation + 01 backpack)
猜你喜欢
![[leetcode] 32. Longest valid bracket](/img/5e/45bb0b1ca3d9e429c6c5cf5c4c93ae.png)
[leetcode] 32. Longest valid bracket

Worthington产气荚膜梭菌神经氨酸酶的特征及测定
![[independent station construction] Shopify seller: learn these points and double the sales volume of online stores!](/img/52/8c1520db38ffa8927e975b6f244a65.png)
[independent station construction] Shopify seller: learn these points and double the sales volume of online stores!

PHP Alipay transfer to Alipay account

Digital transformation behind the reshaping growth of catering chain stores

A pluggable am335x industrial control module onboard WiFi module

租户问题。

TI AM335x工控模块网络跟文件系统NFS的实现

Dest0g3 520 orientation (under update)

还在用==0 null equal 判断空值吗,对isEmpty 和 isBlank有多少了解呢
随机推荐
登堂入室soc之arm汇编基础
E2. escape the maze (hard version)
Composition API的优势
(CVPR 2019) GSPN: Generative Shape Proposal Network for 3D Instance Segmentation in Point Cloud
Dest0g3 520 orientation (under update)
How idea can quickly delete recently opened projects
Ti AM335X工控模块使用beaglebone(bbb)的Debian系统
My Mysql to MySQL data table synchronization, only the code written in the first order will take effect, and the rest will not take effect. This may be
What is JSX?
Ti AM335X工控模块矩阵键盘电路的设计与驱动移植
Detailed explanation of redis6.x configuration parameters
Guys, the flinksql datahub source table has a field timestamp 16 bits, which is written to ora
1. Mx6ul core module serial WiFi test (VIII)
Proto conversion dart | project uses protobuf | fluent uses grpc
阿里云Redis开发规范
QT program beautification of the use of style sheets, QT uses pictures as the background and transparency of controls, QT custom button styles
[Android development IOS series] Language: swift vs kotlin
Kaggle registration method to solve the problem of man-machine verification
vite 本地运行首次进入页面加载慢问题
Why does the debugger display the wrong function