Download services/files.py from ZeloTech/zelotech: direct link, hf CLI and curl.
- Browser
- Download file 673 Bytes
-
https://huggingface.co/spaces/ZeloTech/zelotech/resolve/main/services/files.py
- Command line
-
hf download hf://spaces/ZeloTech/zelotech/services/files.py
-
curl -L -o files.py https://huggingface.co/spaces/ZeloTech/zelotech/resolve/main/services/files.py
673 Bytes
| import os | |
| import tempfile | |
| from fastapi import UploadFile | |
| async def save_upload_to_temp(file: UploadFile) -> str: | |
| """Salva o upload em um arquivo temporario e devolve o caminho.""" | |
| suffix = os.path.splitext(file.filename or "")[1] or ".bin" | |
| fd, path = tempfile.mkstemp(suffix=suffix) | |
| with os.fdopen(fd, "wb") as out: | |
| out.write(await file.read()) | |
| return path | |
| def cleanup(*paths: str | None) -> None: | |
| """Remove arquivos temporarios, ignorando o que nao existir.""" | |
| for p in paths: | |
| if p and os.path.exists(p): | |
| try: | |
| os.remove(p) | |
| except OSError: | |
| pass | |