Description
I try do post some extra data with a UploadFile, how it's possible ?
FastApi return Error: Unprocessable Entity
Example :
class MetadataInfoAdd(BaseModel):
"""
Metadata Info Add Model
"""
document: str
class MetadataInfo(BaseModel):
"""
Metadata Info Model
"""
metadata_key: str
metadata_value: str
metadata_type: str
@app.post("/metadata/add", tags=["stable"], response_model=MetadataInfoAdd)
async def metadata_add(metadata: List[MetadataInfo], file: UploadFile = File(...)):
"""
Perform POST metadata add
"""
return {"document" : "STR"}
Return this

I change my async def (remove file parameter) like this :
@app.post("/metadata/add", tags=["stable"], response_model=MetadataInfoAdd)
async def metadata_add(metadata: List[MetadataInfo]):
"""
Perform POST metadata add
"""
return {"document" : "STR"}
It's work

Is it possible to do this ?
It's a limitation of HTTP itself. To upload files the client sends the body payload encoded with "form data".
Any additional data can only be sent using form data, so, simple fields.
It's documented here in a warning: https://fastapi.tiangolo.com/tutorial/request-forms-and-files/#define-file-and-form-parameters
Ok thanks for reply :)
Most helpful comment
It's a limitation of HTTP itself. To upload files the client sends the body payload encoded with "form data".
Any additional data can only be sent using form data, so, simple fields.
It's documented here in a warning: https://fastapi.tiangolo.com/tutorial/request-forms-and-files/#define-file-and-form-parameters