Spaces:
Runtime error
Runtime error
Download src/utils.py from low-key-007/communityapp2: direct link, hf CLI and curl.
- Browser
- Download file 802 Bytes
-
https://huggingface.co/spaces/low-key-007/communityapp2/resolve/main/src/utils.py
- Command line
-
hf download hf://spaces/low-key-007/communityapp2/src/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/low-key-007/communityapp2/resolve/main/src/utils.py
802 Bytes
| import uuid | |
| from fastapi import UploadFile, HTTPException | |
| from src.config import supabase | |
| async def upload_image(file: UploadFile, bucket: str) -> str: | |
| """Uploads an image to Supabase Storage and returns the public URL.""" | |
| if file.size > 5 * 1024 * 1024: | |
| raise HTTPException(413, "Image too large (Max 5MB)") | |
| ext = file.filename.split('.')[-1] | |
| filename = f"{uuid.uuid4()}.{ext}" | |
| try: | |
| file_content = await file.read() | |
| supabase.storage.from_(bucket).upload( | |
| path=filename, | |
| file=file_content, | |
| file_options={"content-type": file.content_type} | |
| ) | |
| return supabase.storage.from_(bucket).get_public_url(filename) | |
| except Exception as e: | |
| raise HTTPException(500, f"Upload failed: {str(e)}") |