我想要上传用户数据及其文件,并验证用户数据以附加文件。
class User(BaseModel):
user: str
name: str
@router.post("/upload")
async def create_upload_file(data: User, file: UploadFile = File(...)):
print(data)
return {"filename": file.filename}
但它无法运行 错误:不可处理的实体 响应正文:
{
"detail": [
{
"loc": [
"body",
"data"
],
"msg": "value is not a valid dict",
"type": "type_error.dict"
}
]
}
但是如果我分开使用URL,所有工作都能正常运行:
class User(BaseModel):
user: str
name: str
@router.post("/d")
async def create(file: UploadFile = File(...)):
return {"filename": file.filename}
@router.post("/")
def main(user: User):
return user
如何将所有内容组合在一起?