FastAPI(25)- File、Form 混合使用

简介: FastAPI(25)- File、Form 混合使用

前言


详解 Form

详解 File

 

路径函数混合使用 Form、File


from fastapi import FastAPI, File, Form, UploadFile
app = FastAPI()
@app.post("/files/")
async def create_file(
        file: bytes = File(...),
        file_b: UploadFile = File(...),
        token: str = Form(...)
):
    return {
        "file_size": len(file),
        "file_b_content_type": file_b.content_type,
        "token": token
    }
if __name__ == "__main__":
    uvicorn.run(app="21_File:app", host="127.0.0.1", port=8080, reload=True, debug=True)


正确传参的请求结果

image.png

发送表单数据的时候如果有文件,一定要用 form-data !!

 

查看 Swagger API 文档

image.png

相关文章
|
网络架构 Python
【flask入门系列】处理请求之url 路径参数的获取以及转换器的使用
这节我们写一下url路径参数的获取以及转换器的使用,学一下如何在我们的的url路径中加参数以及如何使用转换器,并且自定义转换器。
822 0
【flask入门系列】处理请求之url 路径参数的获取以及转换器的使用
|
JavaScript 前端开发 API
使用ort.js的create方法加载onnx模型报错:Fetch API cannot load file…… URL scheme “file“ is not supported.
使用ort.js的create方法加载onnx模型报错:Fetch API cannot load file…… URL scheme “file“ is not supported.
611 0
使用ort.js的create方法加载onnx模型报错:Fetch API cannot load file…… URL scheme “file“ is not supported.
|
9月前
|
JSON 搜索推荐 API
【2024更新】如何使用google index api来自动提交url
本文提供了一个详细的指南,说明如何创建并使用使用google index api,google自动提交url来优化seo。
|
XML 数据格式
FastAPI(47)- 通过 Response 自定义响应的类型
FastAPI(47)- 通过 Response 自定义响应的类型
331 0
FastAPI(47)- 通过 Response 自定义响应的类型
|
存储
FastAPI(51)- 自定义响应之 StreamingResponse、FileResponse
FastAPI(51)- 自定义响应之 StreamingResponse、FileResponse
1080 1
FastAPI(51)- 自定义响应之 StreamingResponse、FileResponse
FastAPI(10)- 详解 Body(上)
FastAPI(10)- 详解 Body(上)
431 0
FastAPI(10)- 详解 Body(上)
FastAPI(10)- 详解 Body(下)
FastAPI(10)- 详解 Body(下)
292 0
FastAPI(10)- 详解 Body(下)
FastAPI(36)- FastAPI 的元数据配置和文档 URL
FastAPI(36)- FastAPI 的元数据配置和文档 URL
472 0
FastAPI(36)- FastAPI 的元数据配置和文档 URL
FastAPI(7)- 详解 Path(上)
FastAPI(7)- 详解 Path(上)
254 0
FastAPI(7)- 详解 Path(上)
|
JSON API 数据库
FastAPI(19)- Response Model 响应模型 (下)
FastAPI(19)- Response Model 响应模型 (下)
366 0
FastAPI(19)- Response Model 响应模型 (下)