Skip to content

Commit 9274cc9

Browse files
committed
CLI resumable upload
1 parent 1d5293d commit 9274cc9

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function getSSLPage($url) {
183183
->setTwitter('appwrite_io')
184184
->setDiscord('564160730845151244', 'https://appwrite.io/discord')
185185
->setDefaultHeaders([
186-
'X-Appwrite-Response-Format' => '0.12.0',
186+
'X-Appwrite-Response-Format' => '0.13.0',
187187
])
188188
;
189189

templates/cli/lib/commands/command.js.twig

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,35 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
105105
const streamFilePath = payload['{{ parameter.name }}'];
106106
let id = undefined;
107107

108+
let counter = 0;
108109
const totalCounters = Math.ceil(size / libClient.CHUNK_SIZE);
109110

110-
for (let counter = 0; counter < totalCounters; counter++) {
111-
const start = (counter * libClient.CHUNK_SIZE);
112-
const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size);
113-
const headers = {
111+
const headers = {
114112
{% for parameter in method.parameters.header %}
115-
'{{ parameter.name }}': ${{ parameter.name | caseCamel | escapeKeyword }},
113+
'{{ parameter.name }}': ${{ parameter.name | caseCamel | escapeKeyword }},
116114
{% endfor %}
117115
{% for key, header in method.headers %}
118-
'{{ key }}': '{{ header }}',
116+
'{{ key }}': '{{ header }}',
117+
{% endfor %}
118+
};
119+
120+
{% for parameter in method.parameters.all %}
121+
{% if parameter.isUploadID %}
122+
if({{ parameter.name | caseCamel | escapeKeyword }} != 'unique()') {
123+
try {
124+
response = await client.call('get', path + '/' + {{ parameter.name }}, headers);
125+
counter = response.chunksUploaded;
126+
} catch(e) {
127+
}
128+
}
129+
{% endif %}
119130
{% endfor %}
120-
'content-range': 'bytes ' + start + '-' + end + '/' + size
121-
};
131+
132+
for (counter; counter < totalCounters; counter++) {
133+
const start = (counter * libClient.CHUNK_SIZE);
134+
const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size);
135+
136+
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
122137

123138
if (id) {
124139
headers['x-appwrite-id'] = id;

0 commit comments

Comments
 (0)