Spaces:
Runtime error
Runtime error
| import cloudinary.uploader # type: ignore | |
| from typing import Optional | |
| def upload_image( | |
| buffer: bytes, | |
| folder: str, | |
| public_id: Optional[str] = None, | |
| ) -> dict: | |
| try: | |
| upload_options = { | |
| "folder": folder, | |
| "resource_type": "image", | |
| "overwrite": bool(public_id), | |
| "invalidate": bool(public_id), | |
| } | |
| if public_id: | |
| upload_options["public_id"] = public_id | |
| result = cloudinary.uploader.upload( | |
| file=buffer, | |
| **upload_options | |
| ) | |
| return result | |
| except Exception as e: | |
| raise RuntimeError(f"Cloudinary upload failed: {str(e)}") | |