Skip to content

Commit 82db534

Browse files
authored
Use Client's storage when uploading external urls (#62)
1 parent 170e0a2 commit 82db534

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

filestack/models/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def upload_url(self, url, store_params=None, security=None):
120120
:class:`filestack.Filelink`: new Filelink object
121121
"""
122122
sec = security or self.security
123-
upload_response = upload_external_url(url, self.apikey, store_params, security=sec)
123+
upload_response = upload_external_url(url, self.apikey, self.storage, store_params, security=sec)
124124
return filestack.models.Filelink(
125125
handle=upload_response['handle'],
126126
apikey=self.apikey,

filestack/uploads/external_url.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
from filestack.utils import requests
33

44

5-
def upload_external_url(url, apikey, store_params=None, security=None):
5+
def upload_external_url(url, apikey, storage, store_params=None, security=None):
66
store_params = store_params or {}
7+
if storage and not store_params.get('location'):
8+
store_params['location'] = storage
79

810
# remove params that are currently not supported in external url upload
911
for item in ('mimetype', 'upload_tags'):

tests/uploads/test_upload_external_url.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,24 @@
1010
apikey = 'TESTAPIKEY'
1111

1212

13-
@pytest.mark.parametrize('store_params, security, expected_store_tasks', [
13+
@pytest.mark.parametrize('default_storage, store_params, security, expected_store_tasks', [
1414
(
15-
{'location': 's3'},
15+
'S3,',
16+
{'location': 'gcs'},
1617
None,
1718
[
1819
{
19-
'name': 'store', 'params': {'location': 's3'}
20+
'name': 'store', 'params': {'location': 'gcs'}
2021
}
2122
]
2223
),
2324
(
25+
'gcs',
2426
{'path': 'new-path/', 'mimetype': 'application/json'},
2527
type('SecurityMock', (), {'policy_b64': 'abc', 'signature': '123'}),
2628
[
2729
{
28-
'name': 'store', 'params': {'path': 'new-path/'}
30+
'name': 'store', 'params': {'path': 'new-path/', 'location': 'gcs'}
2931
},
3032
{
3133
'name': 'security', 'params': {'policy': 'abc', 'signature': '123'}
@@ -34,15 +36,17 @@
3436
)
3537
])
3638
@patch('filestack.uploads.external_url.requests.post')
37-
def test_upload_with_store_params(post_mock, store_params, security, expected_store_tasks):
39+
def test_upload_with_store_params(post_mock, default_storage, store_params, security, expected_store_tasks):
3840
expected_payload = {
3941
'apikey': 'TESTAPIKEY',
4042
'sources': ['http://image.url'],
4143
'tasks': expected_store_tasks
4244
}
4345
post_mock.return_value = DummyHttpResponse(json_dict={'handle': 'newHandle'})
4446

45-
upload_response = upload_external_url(url, apikey, store_params=store_params, security=security)
47+
upload_response = upload_external_url(
48+
url, apikey, default_storage, store_params=store_params, security=security
49+
)
4650
assert upload_response['handle'] == 'newHandle'
4751
post_args, _ = post_mock.call_args
4852
post_mock.assert_called_once_with('{}/process'.format(config.CDN_URL), json=expected_payload)

0 commit comments

Comments
 (0)