首页 > 解决方案 > FastAPI Async Def 调用常用函数

问题描述

我想将上传部分包装在一个通用函数中,因为它在多个 API 路由中使用,但是由于它在这里使用,我该怎么做async def

@app.post("/api/od")
async def image_classification(files: typing.List[fastapi.UploadFile] = fastapi.File(...)):
    upload_path = pathlib.Path("upload")#.joinpath(token)
    upload_path.mkdir(exist_ok=True)
...

    return results

标签: fastapi

解决方案


推荐阅读