RiShre-Flash / utils.py
rexprimematrix's picture
Upload 26 files
fda0e73 verified
Raw
History Blame Contribute Delete
574 Bytes
import base64
import os
import uuid
def save_base64_image(data_uri):
if not isinstance(data_uri, str):
return data_uri
if not data_uri.startswith("data:image"):
return data_uri
try:
header, encoded = data_uri.split(",", 1)
ext = header.split(";")[0].split("/")[1]
filepath = f"/tmp/{uuid.uuid4().hex}.{ext}"
with open(filepath, "wb") as f:
f.write(base64.b64decode(encoded))
return filepath
except Exception as e:
print(f"Error decoding base64 image: {e}")
return data_uri