The documentation of FastAPI gives a way of receiving multiple files:
@app.post("/uploadfiles/")
async def create_upload_files(files: List[UploadFile] = File(...)):
...
However, it's hard to keep track of the list's order in my application, since the number and content of files can change.
I would like to identify these files with keys, with something like a Dict
:
@app.post("/uploadfiles/")
async def create_upload_files(files: Dict[str, UploadFile] = File(...)):
...
Would that work? If not, how could I do it?
(I want to send binary data and keep it as light as possible, so json.dumps
or similar serialization functions are not acceptable.)
question from:
https://stackoverflow.com/questions/65883452/receiving-a-dictionary-of-files-in-fastapi 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…