Spaces:
Runtime error
Runtime error
Download app/utils/file_utils.py from ch404/cardserver: direct link, hf CLI and curl.
- Browser
- Download file 621 Bytes
-
https://huggingface.co/spaces/ch404/cardserver/resolve/main/app/utils/file_utils.py
- Command line
-
hf download hf://spaces/ch404/cardserver/app/utils/file_utils.py
-
curl -L -o file_utils.py https://huggingface.co/spaces/ch404/cardserver/resolve/main/app/utils/file_utils.py
621 Bytes
| 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}" | |