Wie füge ich sowohl Datei als auch JSON -Body in einer Fastapi -Post -Anfrage hinzu?

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Wie füge ich sowohl Datei als auch JSON -Body in einer Fastapi -Post -Anfrage hinzu?

by Guest » 25 Jan 2025, 16:37

Insbesondere möchte ich, dass das folgende Beispiel funktioniert: < /p>

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
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.

Top