Skip to content

Commit 887e2e6

Browse files
authored
Store upload response in filelink object (#59)
1 parent 836b486 commit 887e2e6

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

filestack/models/client.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,13 @@ 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-
handle = upload_external_url(url, self.apikey, store_params, security=sec)
124-
return filestack.models.Filelink(handle=handle, security=sec)
123+
upload_response = upload_external_url(url, self.apikey, store_params, security=sec)
124+
return filestack.models.Filelink(
125+
handle=upload_response['handle'],
126+
apikey=self.apikey,
127+
security=sec,
128+
upload_response=upload_response
129+
)
125130

126131
def upload(self, *, filepath=None, file_obj=None, store_params=None, intelligent=False, security=None):
127132
"""
@@ -154,4 +159,9 @@ def upload(self, *, filepath=None, file_obj=None, store_params=None, intelligent
154159
)
155160

156161
handle = response_json['handle']
157-
return filestack.models.Filelink(handle, apikey=self.apikey, security=self.security)
162+
return filestack.models.Filelink(
163+
handle,
164+
apikey=self.apikey,
165+
security=self.security,
166+
upload_response=response_json
167+
)

filestack/models/filelink.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Filelink(ImageTransformationMixin, CommonMixin):
1515
>>> flink.url
1616
'https://cdn.filestackcontent.com/sm9IEXAMPLEQuzfJykmA'
1717
"""
18-
def __init__(self, handle, apikey=None, security=None):
18+
def __init__(self, handle, apikey=None, security=None, upload_response=None):
1919
"""
2020
Args:
2121
handle (str): The path of the file to wrap
@@ -26,6 +26,7 @@ def __init__(self, handle, apikey=None, security=None):
2626
self.apikey = apikey
2727
self.handle = handle
2828
self.security = security
29+
self.upload_response = upload_response
2930

3031
def __repr__(self):
3132
return '<Filelink {}>'.format(self.handle)

filestack/uploads/external_url.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ def upload_external_url(url, apikey, store_params=None, security=None):
2828
})
2929

3030
response = requests.post('{}/process'.format(config.CDN_URL), json=payload)
31-
return response.json()['handle']
31+
return response.json()

tests/client_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_store_filepath(upload_mock, client):
5353
@patch('filestack.models.client.multipart_upload')
5454
@patch('filestack.models.client.upload_external_url')
5555
def test_security_inheritance(upload_external_mock, multipart_mock):
56-
upload_external_mock.return_value = 'URL_HANDLE'
56+
upload_external_mock.return_value = {'handle': 'URL_HANDLE'}
5757
multipart_mock.return_value = {'handle': 'FILE_HANDLE'}
5858

5959
policy = {'expiry': 1900}

tests/uploads/test_upload_external_url.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_upload_with_store_params(post_mock, store_params, security, expected_st
4242
}
4343
post_mock.return_value = DummyHttpResponse(json_dict={'handle': 'newHandle'})
4444

45-
handle = upload_external_url(url, apikey, store_params=store_params, security=security)
46-
assert handle == 'newHandle'
45+
upload_response = upload_external_url(url, apikey, store_params=store_params, security=security)
46+
assert upload_response['handle'] == 'newHandle'
4747
post_args, _ = post_mock.call_args
4848
post_mock.assert_called_once_with('{}/process'.format(config.CDN_URL), json=expected_payload)

0 commit comments

Comments
 (0)