File size: 673 Bytes
89e5c14
 
 
 
a6edc9e
557f08a
 
 
 
 
 
 
 
 
 
 
a6edc9e
557f08a
 
 
a6edc9e
89e5c14
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
import cloudinary
import cloudinary.uploader

def upload_to_cloudinary(filepath):
    # Reconfigure inside function
    cloud_name = os.environ.get("CLOUD_NAME")
    api_key = os.environ.get("API_KEY")
    api_secret = os.environ.get("API_SECRET")

    # Debug print (optional)
    print("DEBUG:", cloud_name, api_key, api_secret)

    if not all([cloud_name, api_key, api_secret]):
        raise ValueError("One or more Cloudinary env vars are missing")

    cloudinary.config(
        cloud_name=cloud_name,
        api_key=api_key,
        api_secret=api_secret,
    )

    response = cloudinary.uploader.upload(filepath)
    return response.get("secure_url")