In my fastAPI application, i am defining a post api, where i have to receive files and its metadata from frontend. I will be receiving list of dictionary(or object) where dictionary will be having two field file and metadata. But i am getting error unprocessable entity.
Below is my python code
class FileItem(BaseModel):
file: UploadFile = File(...)
filetype: str = Form(...)
class FileItems(BaseModel):
payload:list[FileItem]
@router.post("/testing/processfiles")
async def process_files(file_items: FileItems):
for item in file_items:
file = item.file
filetype = item.filetype
print(file,filetype)
return {"message": "Files and strings processed successfully"}
in swaggerUI the request body is of application/json instead of multipart/form-data.
Request body
{ "payload": [ { "file": "string", "filetype": "string" } ] }
when i pass list of object from the frontend with the same format, i got Upload error: 404 Unprocessable Entity. How can i achieve this ?