Spaces:
Running
Running
import cloudinary.api | |
import requests | |
# Assuming you have already configured Cloudinary with your credentials | |
def download_file(): | |
save_path = "downloaded.mp3" | |
cloudinary.config( | |
cloud_name = "djepbidi1", | |
api_key = "531731913696587", | |
api_secret = "_5ePxVQEECYYOukhSroYXq7eKL0" | |
) | |
public_id = 'test' | |
# Fetch the asset's details | |
asset_details = cloudinary.api.resource(public_id, resource_type='video') | |
# Extract the secure URL of the asset | |
asset_url = asset_details.get('secure_url') | |
print("Asset URL:", asset_url) | |
""" | |
Download a file from a given URL and save it to the specified local path. | |
Parameters: | |
- url: The URL of the file to download. | |
- save_path: The local path where the file should be saved. | |
""" | |
response = requests.get(asset_url, stream=True) | |
# Check if the request was successful | |
if response.status_code == 200: | |
with open(save_path, 'wb') as f: | |
for chunk in response.iter_content(chunk_size=128): | |
f.write(chunk) | |
print(f"File downloaded successfully: {save_path}") | |
else: | |
print(f"Failed to download file. Status code: {response.status_code}") | |
# Example usage | |
#cloudinary_url = "YOUR_CLOUDINARY_FILE_URL" | |
download_file() | |