首页 > 解决方案 > FastApi 中的多个文件

问题描述

我需要通过 FastApi 上传多个图像文件。我正在使用这段代码:

@app.post("/analyze")
async def analyze(files: List[UploadFile] = File(...)):
for img in files:
    contents = await img.read()
    nparr = np.fromstring(contents, np.uint8)
    img1 = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
    print(img1.shape)
    img1 = resize_image(img1)
    print(img1.shape)

但它显示错误为:

NameError: name 'List' is not defined

请帮忙!

我会尝试通过 fastapi 上传多个图像,然后对其执行 opencv 操作。如果我使用 Postman 代替 SwaggerUI 进行测试,还要在哪里上传图片?

标签: image-processinguploadfastapi

解决方案


推荐阅读