Код: Выделить всё
from fastapi import File, UploadFile, Request, FastAPI, Depends
from typing import List
from fastapi.responses import HTMLResponse
from pydantic import BaseModel, Field
from typing import Optional
app = FastAPI()
class BaseBox(BaseModel):
l: float=Field(...)
t: float=Field(...)
r: float=Field(...)
b: float=Field(...)
class BaseInput(BaseModel):
boxes: List[BaseBox] = Field(...)
words: List[str] = Field(...)
width: Optional[float] = Field(...)
height: Optional[float] = Field(...)
@app.post("/submit")
def submit(
base_input: BaseInput = Depends(),
file: UploadFile = File(...), # Add this line to accept a file
):
return {
"JSON Payload": base_input,
"Filename": file.filename,
}
@app.get("/")
def main(request: Request):
return {"status":"alive"}
Я тоже пробовал
Код: Выделить всё
curl -X 'POST' \
'http://localhost:8007/submit?width=10&height=10' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'file=@test.png;type=image/png' \
-F 'boxes={
"l": 0,
"t": 0,
"r": 0,
"b": 0
}' \
-F 'words=test,test2,tes3,test'
Код: Выделить всё
"POST /submit?width=10&height=10 HTTP/1.1" 422 Unprocessable Entity
Подробнее здесь: https://stackoverflow.com/questions/776 ... asemodel-i