0

I need to upload multiple image files via FastApi. I am using this code:

@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)

But it is showing error as:

NameError: name 'List' is not defined

Please help!

I would try to upload multiple images via fastapi and then perform opencv operations on it. Also where to upload image if I am using Postman instead for SwaggerUI for testing?

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
YamanSinghal
  • 132
  • 1
  • 4
  • 1
    `List` lives in `typing`: `from typing import List` – MatsLindh Oct 21 '21 at 10:10
  • @MatsLindh Can you tell where to upload image if I am using Postman instead of Swagger UI? I am currently using form data to upload image but it is returning 'method not allowed. – YamanSinghal Oct 21 '21 at 12:19
  • That would probably be a Postman specific question if it works otherwise. Postman would need to use a `multipart/form-data` encoding for the post data; not sure how you do that in postman. – MatsLindh Oct 21 '21 at 12:54

1 Answers1

1

Import this

from typing import List
cottontail
  • 10,268
  • 18
  • 50
  • 51