Skip to content

Commit 1a5335b

Browse files
committed
resumable upload support
1 parent 18b2a89 commit 1a5335b

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

appwrite/client.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self):
1111
self._endpoint = 'https://HOSTNAME/v1'
1212
self._global_headers = {
1313
'content-type': '',
14-
'x-sdk-version': 'appwrite:python:0.7.0',
14+
'x-sdk-version': 'appwrite:python:0.8.0',
1515
'X-Appwrite-Response-Format' : '0.13.0',
1616
}
1717

@@ -116,6 +116,7 @@ def chunked_upload(
116116
params = None,
117117
param_name = '',
118118
on_progress = None,
119+
upload_id = ''
119120
):
120121
file_path = str(params[param_name])
121122
file_name = os.path.basename(file_path)
@@ -133,6 +134,18 @@ def chunked_upload(
133134

134135
input = open(file_path, 'rb')
135136
offset = 0
137+
counter = 0
138+
139+
if upload_id != 'unique()':
140+
try:
141+
result = self.call('get', path + '/' + upload_id, headers)
142+
counter = result['chunksUploaded']
143+
except:
144+
pass
145+
146+
if counter > 0:
147+
offset = counter * self._chunk_size
148+
input.seek(offset)
136149

137150
while offset < size:
138151
slice = input.read(self._chunk_size) or input.read(size - offset)
@@ -153,6 +166,7 @@ def chunked_upload(
153166
headers["x-appwrite-id"] = result["$id"]
154167

155168
if on_progress is not None:
169+
end = min((((counter * self._chunk_size) + self._chunk_size) - 1), size)
156170
on_progress({
157171
"$id": result["$id"],
158172
"progress": min(offset, size)/size * 100,
@@ -161,6 +175,8 @@ def chunked_upload(
161175
"chunksUploaded": result["chunksUploaded"],
162176
})
163177

178+
counter = counter + 1
179+
164180
return result
165181

166182
def flatten(self, data, prefix='', stringify=False):

appwrite/services/functions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,12 @@ def create_deployment(self, function_id, entrypoint, code, activate, on_progress
218218

219219
param_name = 'code'
220220

221+
222+
upload_id = ''
223+
221224
return self.client.chunked_upload(path, {
222225
'content-type': 'multipart/form-data',
223-
}, params, param_name, on_progress)
226+
}, params, param_name, on_progress, upload_id)
224227

225228
def get_deployment(self, function_id, deployment_id):
226229
"""Get Deployment"""

appwrite/services/storage.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,13 @@ def create_file(self, bucket_id, file_id, file, read = None, write = None, on_pr
220220

221221
param_name = 'file'
222222

223+
224+
upload_id = ''
225+
upload_id = file_id
226+
223227
return self.client.chunked_upload(path, {
224228
'content-type': 'multipart/form-data',
225-
}, params, param_name, on_progress)
229+
}, params, param_name, on_progress, upload_id)
226230

227231
def get_file(self, bucket_id, file_id):
228232
"""Get File"""

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
setuptools.setup(
44
name = 'appwrite',
55
packages = ['appwrite', 'appwrite/services'],
6-
version = '0.7.0',
6+
version = '0.8.0',
77
license='BSD-3-Clause',
88
description = 'Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API',
99
author = 'Appwrite Team',
1010
author_email = '[email protected]',
1111
maintainer = 'Appwrite Team',
1212
maintainer_email = '[email protected]',
1313
url = 'https://appwrite.io/support',
14-
download_url='https://github.com/appwrite/sdk-for-python/archive/0.7.0.tar.gz',
14+
download_url='https://github.com/appwrite/sdk-for-python/archive/0.8.0.tar.gz',
1515
# keywords = ['SOME', 'MEANINGFULL', 'KEYWORDS'],
1616
install_requires=[
1717
'requests',

0 commit comments

Comments
 (0)