【问题标题】:How to request multiple file in FastAPI?如何在 FastAPI 中请求多个文件?
【发布时间】:2021-12-30 07:05:23
【问题描述】:

我有一个功能,我需要用户上传多个文件/图像。请求文件的长度可以是动态的。

def add_images(image1: UploadFile = File(...),image2: UploadFile = File(...),image3: UploadFile = File(...)):
    return {"msg": "success"}

到目前为止,这是我要求的主体,但我知道这不是理想的方式。

【问题讨论】:

    标签: python python-3.x fastapi


    【解决方案1】:

    您可以通过将图片请求为 UploadFile 列表来上传多张图片。

    from typing import List
    
    def add_images(images: List[UploadFile] = File(...)):
        // Your image upload code here
        return {"msg": "success"}
    

    【讨论】:

    • 谢谢@Dharmik,这个解决方案对我有用。
    猜你喜欢
    • 2021-06-19
    • 1970-01-01
    • 2021-04-06
    • 2018-01-24
    • 2022-11-24
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    相关资源
    最近更新 更多