[Python] How to add both file and JSON body in a FastAPI POST request?

Discussão em 'Python' iniciado por Stack, Setembro 14, 2024.

  1. Stack

    Stack Membro Participativo

    Specifically, I want the below example to work:

    from typing import List
    from pydantic import BaseModel
    from fastapi import FastAPI, UploadFile, File


    app = FastAPI()


    class DataConfiguration(BaseModel):
    textColumnNames: List[str]
    idColumn: str


    @app.post("/data")
    async def data(dataConfiguration: DataConfiguration,
    csvFile: UploadFile = File(...)):
    pass
    # read requested id and text columns from csvFile


    If this is not the proper way for a POST request, please let me know how to select the required columns from an uploaded CSV file in FastAPI.

    Continue reading...

Compartilhe esta Página