1

I have the following code where trying to convert and UploadFile from a REST call to pillow image. The request is sent via POSTMAN with form-data in body section and a simple png image as input.

from fastapi import File, APIRouter
from PIL import Image
from io import BytesIO

@api.post("/myEndPoint")
def function(
  img: UploadFile
)
img_pillow = Image.open(BytesIO(img.file.read()))

However, I get the following error: PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000002A05D4A59A0>.

Any idea how I can do this conversion smoothly?

singa1994
  • 747
  • 1
  • 7
  • 18
  • Related answers can also be found [here](https://stackoverflow.com/a/73811351/17865804) and [here](https://stackoverflow.com/a/71639658/17865804) – Chris Mar 15 '23 at 17:17

0 Answers0