Skip to content

Commit e19c7e7

Browse files
author
Bartek Kwiecien
committed
Merge branch 'release/3.4.0'
2 parents 95adec0 + e96c6b2 commit e19c7e7

File tree

9 files changed

+25
-11
lines changed

9 files changed

+25
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Filestack-Python Changelog
22

3+
### 3.4.0 (May 13th, 2021)
4+
- Store upload response in Filelink object [#59](https://github.com/filestack/filestack-python/pull/59)
5+
36
### 3.3.0 (March 12th, 2021)
47
- Added Image OCR [#52](https://github.com/filestack/filestack-python/pull/52)
58
- Changed how files from external urls are uploaded [#54](https://github.com/filestack/filestack-python/pull/54)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.3.0
1+
3.4.0

docs/source/uploading_files.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ To upload in-memory bytes:
4747
bytes_to_upload = b'content'
4848
4949
cli = Client('<FILESTACK_APIKEY>')
50-
filelink = cli.uploads(file_obj=io.BytesIO(bytes_to_upload))
50+
filelink = cli.upload(file_obj=io.BytesIO(bytes_to_upload))
5151
5252
5353
External urls

filestack/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '3.3.0'
1+
__version__ = '3.4.0'
22

33

44
class CFG:

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)