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'}")