Skip to content

Commit b80ea91

Browse files
committed
Merge remote-tracking branch 'origin/0.14.x' into feat-resumable-upload-kotlin
2 parents 1fc682c + 43ae5db commit b80ea91

File tree

3 files changed

+46
-31
lines changed

3 files changed

+46
-31
lines changed

templates/dart/lib/src/chunked_upload_io.dart.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ Future<Response> chunkedUpload({
6666
}
6767
final progress = UploadProgress(
6868
$id: res.data['\$id'] ?? '',
69-
progress: min(offset,size)/size * 100,
70-
sizeUploaded: min(offset,size),
69+
progress: min(offset-1,size)/size * 100,
70+
sizeUploaded: min(offset-1,size),
7171
chunksTotal: res.data['chunksTotal'] ?? 0,
7272
chunksUploaded: res.data['chunksUploaded'] ?? 0,
7373
);

templates/php/src/Services/Service.php.twig

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -72,36 +72,51 @@ class {{ service.name | caseUcfirst }} extends Service
7272
'{{ key }}' => '{{ header }}',
7373
{% endfor %}
7474
], $params);
75-
} else {
76-
$id = '';
77-
$handle = @fopen(${{ parameter.name | caseCamel }}, "rb");
78-
$counter = 0;
79-
$headers = ['content-type' => 'multipart/form-data'];
80-
while (!feof($handle)) {
81-
$params['{{ parameter.name }}'] = new \CURLFile('data://' . $mimeType . ';base64,' . base64_encode(@fread($handle, Client::CHUNK_SIZE)), $mimeType, $postedName);
82-
$headers['content-range'] = 'bytes ' . ($counter * Client::CHUNK_SIZE) . '-' . min(((($counter * Client::CHUNK_SIZE) + Client::CHUNK_SIZE) - 1), $size) . '/' . $size;
83-
if(!empty($id)) {
84-
$headers['x-{{spec.title | caseLower }}-id'] = $id;
85-
}
86-
$response = $this->client->call(Client::METHOD_POST, $path, $headers, $params);
87-
$counter++;
88-
if(empty($id)) {
89-
$id = $response['$id'];
90-
}
91-
if($onProgress !== null) {
92-
$end = min(((($counter * Client::CHUNK_SIZE) + Client::CHUNK_SIZE) - 1), $size);
93-
$onProgress([
94-
'$id' => $response['$id'],
95-
'progress' => min(($counter+1) * Client::CHUNK_SIZE, $size) / $size * 100,
96-
'sizeUploaded' => $end + 1,
97-
'chunksTotal' => $response['chunksTotal'],
98-
'chunksUploaded' => $response['chunksUploaded']
99-
]);
75+
}
76+
77+
$id = '';
78+
$counter = 0;
79+
80+
{% for parameter in method.parameters.all %}
81+
{% if parameter.isUploadID %}
82+
if(${{ parameter.name | caseCamel | escapeKeyword }} != 'unique()') {
83+
try {
84+
$response = $this->client->call(Client::METHOD_GET, new URL($path . '/' . {{ parameter.name }}), headers);
85+
$counter = $response['chunksUploaded'] ?? 0;
86+
} catch(\Exception $e) {
10087
}
10188
}
102-
@fclose($handle);
103-
return $response;
89+
{% endif %}
90+
{% endfor %}
91+
92+
$headers = ['content-type' => 'multipart/form-data'];
93+
$handle = @fopen(${{ parameter.name | caseCamel }}, "rb");
94+
$start = $counter * Client::CHUNK_SIZE;
95+
while ($start < $size) {
96+
fseek($handle, $start);
97+
$params['{{ parameter.name }}'] = new \CURLFile('data://' . $mimeType . ';base64,' . base64_encode(@fread($handle, Client::CHUNK_SIZE)), $mimeType, $postedName);
98+
$headers['content-range'] = 'bytes ' . ($counter * Client::CHUNK_SIZE) . '-' . min(((($counter * Client::CHUNK_SIZE) + Client::CHUNK_SIZE) - 1), $size) . '/' . $size;
99+
if(!empty($id)) {
100+
$headers['x-{{spec.title | caseLower }}-id'] = $id;
101+
}
102+
$response = $this->client->call(Client::METHOD_POST, $path, $headers, $params);
103+
$counter++;
104+
$start += Client::CHUNK_SIZE;
105+
if(empty($id)) {
106+
$id = $response['$id'];
107+
}
108+
if($onProgress !== null) {
109+
$onProgress([
110+
'$id' => $response['$id'],
111+
'progress' => min(((($counter * Client::CHUNK_SIZE) + Client::CHUNK_SIZE) - 1), $size) / $size * 100,
112+
'sizeUploaded' => min($counter * Client::CHUNK_SIZE),
113+
'chunksTotal' => $response['chunksTotal'],
114+
'chunksUploaded' => $response['chunksUploaded'],
115+
]);
116+
}
104117
}
118+
@fclose($handle);
119+
return $response;
105120
{% endif %}
106121
{% endfor %}
107122
{% else %}

templates/web/src/sdk.ts.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,8 @@ class {{ spec.title | caseUcfirst }} {
575575
if (onProgress) {
576576
onProgress({
577577
$id: response.$id,
578-
progress: Math.min((counter + 1) * Appwrite.CHUNK_SIZE, size) / size * 100,
579-
sizeUploaded: end+1,
578+
progress: Math.min((counter + 1) * {{ spec.title | caseUcfirst }}.CHUNK_SIZE - 1, size) / size * 100,
579+
sizeUploaded: end,
580580
chunksTotal: response.chunksTotal,
581581
chunksUploaded: response.chunksUploaded
582582
});

0 commit comments

Comments
 (0)