Ashhar
icon change
397dfe3
raw
history blame
655 Bytes
import cloudinary
from cloudinary import CloudinaryImage
import cloudinary.uploader
import cloudinary.api
import utils as U
def initCloudinary():
cloudinary.config(secure=True)
def __getImageId(imagePath: str):
imagePath = imagePath.replace('\\', '/')
parts = imagePath.split('/')
return parts[-2]
def getCdnUrl(imagePath: str) -> str:
imageId = __getImageId(imagePath)
cloudinary.uploader.upload(imagePath, public_id=imageId, unique_filename=False, overwrite=True)
U.pprint(f"Image uploaded to CDN: {imageId}")
srcURL = CloudinaryImage(imageId).build_url()
U.pprint(f"Image CDN URL: {srcURL}")
return srcURL