File size: 621 Bytes
a38f710
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import uuid, os
from pathlib import Path
from dotenv import load_dotenv

load_dotenv()
GENERATED_DIR = Path(os.getenv("GENERATED_PATH", "media"))
HOST_URL = os.getenv("HOST_URL", "http://localhost:8000")

def save_card_image(image_bytes: bytes, extension="png") -> Path:
    filename = f"{uuid.uuid4()}.{extension}"
    filepath = GENERATED_DIR / filename
    filepath.parent.mkdir(parents=True, exist_ok=True)
    with open(filepath, "wb") as f:
        f.write(image_bytes)
    return filepath

def get_card_url(filename: str, base_url: str = "https://yourdomain.com/media") -> str:
    return f"{base_url}/{filename}"