Reputation: 163
I need to pass multiple files with an index with some additional JSON data to FastAPI in Python. This is not like passing multiple files with JSON what I want is the ability to pass multiple group of files in each web request.
The files need some kind of index which are very dynamic , i.e. in one request I might need files for a node say node 1 and in another one node 1 and node 2. where each node can have multiple files. This is because I am sending a graph structure as input with multiple nodes and each node can have zero or more files associated with it.
And I do not want to pass the file data as base64 encoded within my JSON
Tried using indexed parameter with fast API as suggested by CoPilot. Copilot suggestion is to use as below :
sync def process(
request: Request,
data: str = Body(...),#Data, # JSON payload
node_files: Dict[str, List[UploadFile]] = Depends(lambda: {}) # Node-specific files
):
where it says then I can use node_files[1] or node_files[2] as needed so that my FastAPI signature remains the same , But some how this is not working , When I tried with POSTMAN , with keys node_files[1] with different files and node_files[2] with another set of files. But the node_files parameter in fast API always provides null.
Upvotes: 1
Views: 41