当前位置:网站首页>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的问题。
边栏推荐
- Worthington nuclease and Micrococcus related research and determination scheme
- I.MX6UL核心模块使用连载-以太网测试 (七)
- Mark and lightbulbs (thinking)
- DQN Pytorch示例
- proto转换Dart | 项目使用Protobuf | flutter 使用grpc
- ggplot2学习总结
- 还在用==0 null equal 判断空值吗,对isEmpty 和 isBlank有多少了解呢
- Characteristics and determination of neuraminidase from Clostridium perfringens in Worthington
- Build embedded development environment and FRP penetration under win
- These practical security browser plug-ins improve your efficiency
猜你喜欢

excel中怎么显示数字/英文时间
![[leetcode] 32. Longest valid bracket](/img/5e/45bb0b1ca3d9e429c6c5cf5c4c93ae.png)
[leetcode] 32. Longest valid bracket

I.MX6UL核心模块使用连载-USB接口测试 (六)
![Niuke - bm39 serialized binary tree [hard]](/img/c4/f14fe8488bbf28689fa3f02cdf4dae.png)
Niuke - bm39 serialized binary tree [hard]

BGP knowledge points summary

保护系统日志服务器和设备

1. Mx6ul core module serial WiFi test (VIII)

1. Mx6ul core module use serial TF card read / write test (V)

还在用==0 null equal 判断空值吗,对isEmpty 和 isBlank有多少了解呢

Ti AM335X工控模块矩阵键盘电路的设计与驱动移植
随机推荐
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
Characteristics and determination of neuraminidase from Clostridium perfringens in Worthington
Dqn pytoch example
# Dest0g3 520迎新赛(更新中)
Advantages of composition API
TI AM335x工控模块网络跟文件系统NFS的实现
MySQL locking table problem
I.MX6UL核心模块使用连载-eMMC读写测试 (四)
Move bricks (greedy perturbation + 01 backpack)
BGP knowledge points summary
国标GB28181协议视频平台EasyGBS消息弹框模式优化
IDEA如何快速删除最近打开的项目
proto转换Dart | 项目使用Protobuf | flutter 使用grpc
一种MCU事件型驱动C框架
Why does the debugger display the wrong function
How to use the pagoda panel to deploy the full stack project of node to the server
Qt程序美化之样式表的使用方法,Qt使用图片作为背景与控件透明化,Qt自定义按钮样式
LeetCode302场周赛第三题--裁剪数字后查询第 K 小的数字
D. Rating compression (thinking + double pointer)
Make and makefile summary I