0

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"
  ]
}
Chris
  • 18,724
  • 6
  • 46
  • 80
Mohammadreza Riahi
  • 502
  • 1
  • 6
  • 20
  • 1
    In addition to the link above, please have a look at this [related answer](https://stackoverflow.com/a/71439821/17865804) as well. – Chris Jun 21 '23 at 18:58

0 Answers0