@CrazyChucky, thanks for point out the async sync .
I worked again on this
from fastapi import File,UploadFile
from PIL import Image,ImageFont, ImageDraw
from io import BytesIO
@router.post("/users/update_user_profile")
async def upload_file(self, image_file : UploadFile = File(None)):
out_image_name = 'image_name'+pathlib.Path(image_file.filename).suffix
out_image_path = f"images/user/{out_image_name}"
request_object_content = await image_file.read()
photo = Image.open(BytesIO(request_object_content))
# make the image editable
drawing = ImageDraw.Draw(photo)
black = (3, 8, 12)
drawing.text((0,0), 'Your_text', fill=black)#, font=font)
# Create a buffer to hold the bytes
buf = BytesIO()
# Save the image as jpeg to the buffer
photo.save(buf, format='JPEG')#
async with aiofiles.open(out_image_path, 'wb') as out_file:
outContent = await out_file.write(buf.getbuffer()) # async write
return out_image_name
I referred @Karol suggestion.
Check now, this is for fastapi async method