Spaces:
Sleeping
Sleeping
File size: 1,599 Bytes
54fe70d |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import os
import cloudinary
import cloudinary.uploader
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
# 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"),
secure=True
)
def test_cloudinary_upload():
"""Test Cloudinary upload functionality"""
try:
# Try to upload a simple text as a test
# Create a simple test file
test_file = "test_image.txt"
with open(test_file, "w") as f:
f.write("This is a test file for Cloudinary upload")
# Upload to Cloudinary
print("Uploading to Cloudinary...")
result = cloudinary.uploader.upload(
test_file,
folder="marine_guard_test",
public_id="test_upload"
)
print(f"Upload successful! URL: {result['secure_url']}")
print(f"Full result: {result}")
# Clean up the test file
os.remove(test_file)
return True
except Exception as e:
print(f"Error testing Cloudinary upload: {e}")
return False
if __name__ == "__main__":
print("Testing Cloudinary configuration")
print(f"Cloud name: {os.getenv('CLOUDINARY_CLOUD_NAME')}")
print(f"API key: {os.getenv('CLOUDINARY_API_KEY')}")
print(f"API secret: {os.getenv('CLOUDINARY_API_SECRET')[:3]}...")
test_result = test_cloudinary_upload()
print(f"Test {'successful' if test_result else 'failed'}") |