I am developing a post api using fastAPI. To this end, I create a class for the input request of my API.
from pydantic import BaseModel
from typing import List
class InputRequest(BaseModel):
user_id: str
index_id: str
dirs: List[str]
files: List[UploadFile] = File(...)
@app.post("/test")
async def test(input_request: InputRequest):
return {"message": "Assistant processed successfully"}
To test the API, I use the http://localhost:8000/docs
. However, the request body defined as the application/json
. My question is how can I upload files for this API using fastAPI docs? When the request body is multipar/from-data, there is an "Upload File" button, while in this case the it is a json like this:
{
"user_id": "string",
"index_id": "string",
"dirs": [
"string"
],
"files": [
"string"
]
}