import base64 from fastapi import UploadFile def image_path_to_base64(image_path: str) -> str: with open(image_path, "rb") as image_file: return base64.b64encode(image_file.read()).decode("utf-8") def upload_file_to_base64(file: UploadFile) -> str: return base64.b64encode(file.file.read()).decode("utf-8") def image_path_to_uri(image_path: str) -> str: return f"data:image/jpeg;base64,{image_path_to_base64(image_path)}"