Skip to content

Commit 1057f12

Browse files
author
bkwi
authored
Merge pull request #49 from filestack/encode-external-urls
Encode external urls
2 parents 0d4fb6d + 2112851 commit 1057f12

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

filestack/uploads/external_url.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import base64
12
from collections import OrderedDict
23

34
from filestack.utils import requests
@@ -24,7 +25,8 @@ def build_store_task(store_params):
2425

2526
def upload_external_url(url, apikey, store_params=None, security=None):
2627
store_task = build_store_task(store_params or {})
27-
url_elements = [config.CDN_URL, apikey, store_task, url]
28+
encoded_url = 'b64://{}'.format(base64.urlsafe_b64encode(url.encode()).decode())
29+
url_elements = [config.CDN_URL, apikey, store_task, encoded_url]
2830

2931
if security is not None:
3032
url_elements.insert(3, security.as_url_string())

tests/uploads/test_upload_external_url.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import base64
12
from unittest.mock import patch
23

34
import pytest
@@ -8,6 +9,7 @@
89
from filestack.uploads.external_url import upload_external_url
910

1011
url = 'http://image.url'
12+
encoded_url = 'b64://{}'.format(base64.urlsafe_b64encode(url.encode()).decode())
1113
apikey = 'TESTAPIKEY'
1214

1315

@@ -17,7 +19,7 @@ def test_upload(post_mock):
1719

1820
handle = upload_external_url(url, apikey)
1921
assert handle == 'newHandle'
20-
post_mock.assert_called_once_with('{}/{}/store/{}'.format(config.CDN_URL, apikey, url))
22+
post_mock.assert_called_once_with('{}/{}/store/{}'.format(config.CDN_URL, apikey, encoded_url))
2123

2224

2325
@pytest.mark.parametrize('store_params, expected_store_task', [
@@ -47,7 +49,7 @@ def test_upload_with_security(post_mock):
4749
handle = upload_external_url(url, apikey, security=security)
4850
assert handle == 'newHandle'
4951
expected_url = '{}/{}/store/{}/{}'.format(
50-
config.CDN_URL, apikey, security.as_url_string(), url
52+
config.CDN_URL, apikey, security.as_url_string(), encoded_url
5153
)
5254
post_mock.assert_called_once_with(expected_url)
5355

0 commit comments

Comments
 (0)