Wie füge ich sowohl Datei als auch JSON -Body in einer Fastapi -Post -Anfrage hinzu?
Posted: 25 Jan 2025, 16:37
Insbesondere möchte ich, dass das folgende Beispiel funktioniert: < /p>
Wenn dies nicht die richtige Möglichkeit für eine Post Anforderung ist, teilen Sie mir bitte mit, wie Sie die erforderlichen Spalten aus einer hochgeladenen CSV -Datei in Fastapi auswählen.
Code: Select all
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(...)):
# read requested id and text columns from csvFile
pass