@@ -106,46 +106,61 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
106
106
const streamFilePath = payload['{{ parameter .name }}'];
107
107
let id = undefined;
108
108
109
+ let counter = 0;
109
110
const totalCounters = Math.ceil(size / libClient.CHUNK_SIZE);
110
111
111
- for (let counter = 0; counter < totalCounters; counter++) {
112
- const start = (counter * libClient.CHUNK_SIZE);
113
- const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size);
114
- const headers = {
112
+ const headers = {
115
113
{% for parameter in method .parameters .header %}
116
- '{{ parameter .name }}': ${{ parameter .name | caseCamel | escapeKeyword }},
114
+ '{{ parameter .name }}': ${{ parameter .name | caseCamel | escapeKeyword }},
117
115
{% endfor %}
118
116
{% for key , header in method .headers %}
119
- '{{ key }}': '{{ header }}',
117
+ '{{ key }}': '{{ header }}',
118
+ {% endfor %}
119
+ };
120
+
121
+ {% for parameter in method .parameters .all %}
122
+ {% if parameter .isUploadID %}
123
+ if({{ parameter .name | caseCamel | escapeKeyword }} != 'unique()') {
124
+ try {
125
+ response = await client.call('get', path + '/' + {{ parameter .name }}, headers);
126
+ counter = response.chunksUploaded;
127
+ } catch(e) {
128
+ }
129
+ }
130
+ {% endif %}
120
131
{% endfor %}
121
- 'content-range': 'bytes ' + start + '-' + end + '/' + size
122
- };
123
132
124
- if (id) {
125
- headers['x-appwrite-id'] = id;
126
- }
133
+ for (counter; counter < totalCounters; counter++) {
134
+ const start = (counter * libClient.CHUNK_SIZE);
135
+ const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size);
136
+
137
+ headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
138
+
139
+ if (id) {
140
+ headers['x-appwrite-id'] = id;
141
+ }
142
+
143
+ const stream = fs.createReadStream(streamFilePath, {
144
+ start,
145
+ end
146
+ });
147
+ payload['{{ parameter .name }}'] = stream;
148
+
149
+ response = await client.call('{{ method .method | caseLower }}', path, headers, payload{% if method .type == ' location' %}, 'arraybuffer'{% endif %});
150
+
151
+ if (!id) {
152
+ id = response['$id'];
153
+ }
127
154
128
- const stream = fs.createReadStream(streamFilePath, {
129
- start,
130
- end
155
+ if (onProgress !== null) {
156
+ onProgress({
157
+ $id: response['$id'],
158
+ progress: Math.min((counter+1) * libClient.CHUNK_SIZE, size) / size * 100,
159
+ sizeUploaded: end+1,
160
+ chunksTotal: response['chunksTotal'],
161
+ chunksUploaded: response['chunksUploaded']
131
162
});
132
- payload['{{ parameter .name }}'] = stream;
133
-
134
- response = await client.call('{{ method .method | caseLower }}', path, headers, payload{% if method .type == ' location' %}, 'arraybuffer'{% endif %});
135
-
136
- if (!id) {
137
- id = response['$id'];
138
- }
139
-
140
- if (onProgress !== null) {
141
- onProgress({
142
- $id: response['$id'],
143
- progress: Math.min((counter+1) * libClient.CHUNK_SIZE, size) / size * 100,
144
- sizeUploaded: end+1,
145
- chunksTotal: response['chunksTotal'],
146
- chunksUploaded: response['chunksUploaded']
147
- });
148
- }
163
+ }
149
164
}
150
165
}
151
166
{% endif %}
0 commit comments