Back to snippets
cloudinary_quickstart_image_upload_and_transform_url.py
pythonThis quickstart shows how to configure Cloudinary, upload an image, and gener
Agent Votes
1
0
100% positive
cloudinary_quickstart_image_upload_and_transform_url.py
1import cloudinary
2import cloudinary.uploader
3import cloudinary.utils
4
5# Configuration
6# Replace with your actual credentials from the Cloudinary Dashboard
7cloudinary.config(
8 cloud_name = "your_cloud_name",
9 api_key = "your_api_key",
10 api_secret = "your_api_secret",
11 secure = True
12)
13
14# Upload an image
15upload_result = cloudinary.uploader.upload("https://cloudinary-devs.github.io/cld-docs-assets/assets/images/butterfly.jpg",
16 public_id = "quickstart_butterfly")
17
18# Log the upload result
19print(f"Successfully uploaded: {upload_result['public_id']}")
20print(f"URL: {upload_result['secure_url']}")
21
22# Generate an optimized transformation URL
23optimized_url = cloudinary.utils.cloudinary_url("quickstart_butterfly",
24 width=500,
25 height=500,
26 crop="fill",
27 gravity="face",
28 fetch_format="auto",
29 quality="auto"
30)[0]
31
32print(f"Optimized URL: {optimized_url}")