Skip to content

Commit 81fe639

Browse files
Fix sync of private assets
1 parent 36f8194 commit 81fe639

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

cloudinary_cli/utils/api_utils.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,23 @@ def upload_file(file_path, options, uploaded=None, skipped=None):
6969

7070
def download_file(remote_file, local_path):
7171
makedirs(path.dirname(local_path), exist_ok=True)
72+
73+
sign_url = True if remote_file['type'] in ("private", "authenticated") else False
74+
75+
download_url = cloudinary_url(asset_source(remote_file), resource_type=remote_file['resource_type'],
76+
type=remote_file['type'], sign_url=sign_url)[0]
77+
78+
result = requests.get(download_url)
79+
80+
if result.status_code != 200:
81+
msg = f"Failed downloading: {download_url}, status code: {result.status_code}, " \
82+
f"details: {result.headers.get('x-cld-error')}"
83+
logger.error(msg)
84+
85+
return
86+
7287
with open(local_path, "wb") as f:
73-
download_url = cloudinary_url(asset_source(remote_file), resource_type=remote_file['resource_type'],
74-
type=remote_file['type'])[0]
75-
f.write(requests.get(download_url).content)
88+
f.write(result.content)
7689
logger.info(style("Downloaded '{}' to '{}'".format(remote_file['relative_path'], local_path), fg="green"))
7790

7891

0 commit comments

Comments
 (0)