Download utils/cloudinary_utils.py from anique-1/Medisync: direct link, hf CLI and curl.
- Browser
- Download file 802 Bytes
-
https://huggingface.co/spaces/anique-1/Medisync/resolve/main/utils/cloudinary_utils.py
- Command line
-
hf download hf://spaces/anique-1/Medisync/utils/cloudinary_utils.py
-
curl -L -o cloudinary_utils.py https://huggingface.co/spaces/anique-1/Medisync/resolve/main/utils/cloudinary_utils.py
802 Bytes
| import cloudinary | |
| import cloudinary.uploader | |
| import os | |
| from fastapi import UploadFile | |
| # Configure Cloudinary | |
| cloudinary.config( | |
| cloud_name=os.getenv("CLOUDINARY_CLOUD_NAME"), | |
| api_key=os.getenv("CLOUDINARY_API_KEY"), | |
| api_secret=os.getenv("CLOUDINARY_API_SECRET") | |
| ) | |
| def upload_image_to_cloudinary(file: UploadFile, folder: str = "medispenser") -> str: | |
| """ | |
| Uploads a file directly to Cloudinary and returns the secure URL. | |
| """ | |
| try: | |
| # Upload the file directly from the memory stream | |
| upload_result = cloudinary.uploader.upload( | |
| file.file, | |
| folder=folder, | |
| resource_type="auto" | |
| ) | |
| return upload_result.get("secure_url") | |
| except Exception as e: | |
| print(f"Cloudinary upload failed: {e}") | |
| return "" | |