Spaces:
Runtime error
Runtime error
Download utils/file_utils.py from cloudaiRambo/cloudairambo: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/cloudaiRambo/cloudairambo/resolve/main/utils/file_utils.py
- Command line
-
hf download hf://spaces/cloudaiRambo/cloudairambo/utils/file_utils.py
-
curl -L -o file_utils.py https://huggingface.co/spaces/cloudaiRambo/cloudairambo/resolve/main/utils/file_utils.py
1.02 kB
| import os | |
| import uuid | |
| from core.config import settings | |
| # ------------------------------------------------- | |
| # LOW-LEVEL BYTE SAVER (NEW, CORRECT) | |
| # ------------------------------------------------- | |
| def save_bytes_to_file(data: bytes, original_name: str): | |
| os.makedirs(settings.TEMP_DIR, exist_ok=True) | |
| filename = f"{uuid.uuid4().hex}_{original_name}" | |
| path = os.path.join(settings.TEMP_DIR, filename) | |
| with open(path, "wb") as f: | |
| f.write(data) | |
| if os.path.getsize(path) == 0: | |
| raise RuntimeError("Saved file is empty") | |
| return path | |
| # ------------------------------------------------- | |
| # BACKWARD-COMPAT WRAPPER (IMPORTANT) | |
| # ------------------------------------------------- | |
| def save_upload_file(file): | |
| """ | |
| Compatibility wrapper for existing routers. | |
| DO NOT remove — many routers depend on this. | |
| """ | |
| data = file.file.read() | |
| if not data: | |
| raise RuntimeError("Uploaded file stream is empty") | |
| return save_bytes_to_file(data, file.filename) | |