Skip to content

Commit dee773a

Browse files
committed
fix dart and flutter chunk upload
1 parent 398feb9 commit dee773a

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

templates/dart/lib/src/client_browser.dart.twig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,18 @@ class ClientBrowser extends ClientBase with ClientMixin {
114114
headers: headers,
115115
);
116116
final int chunksUploaded = res.data['chunksUploaded'] as int;
117-
offset = min(size - 1, chunksUploaded * CHUNK_SIZE);
117+
offset = chunksUploaded * CHUNK_SIZE;
118118
} on {{spec.title | caseUcfirst}}Exception catch (_) {}
119119
}
120120

121121
while (offset < size) {
122-
List<int> chunk;
123-
final end = min(offset + CHUNK_SIZE, size - 1);
122+
var chunk;
123+
final end = min(offset + CHUNK_SIZE - 1, size - 1);
124124
chunk = file.bytes!.getRange(offset, end).toList();
125125
params[paramName] =
126126
http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename);
127127
headers['content-range'] =
128-
'bytes $offset-${min<int>((offset + CHUNK_SIZE), size - 1)}/$size';
128+
'bytes $offset-${min<int>((offset + CHUNK_SIZE - 1), size - 1)}/$size';
129129
res = await call(HttpMethod.post,
130130
path: path, headers: headers, params: params);
131131
offset += CHUNK_SIZE;
@@ -134,8 +134,8 @@ class ClientBrowser extends ClientBase with ClientMixin {
134134
}
135135
final progress = UploadProgress(
136136
$id: res.data['\$id'] ?? '',
137-
progress: min(offset + 1, size) / size * 100,
138-
sizeUploaded: min(offset + 1, size),
137+
progress: min(offset, size) / size * 100,
138+
sizeUploaded: min(offset, size),
139139
chunksTotal: res.data['chunksTotal'] ?? 0,
140140
chunksUploaded: res.data['chunksUploaded'] ?? 0,
141141
);

templates/dart/lib/src/client_io.dart.twig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class ClientIO extends ClientBase with ClientMixin {
142142
headers: headers,
143143
);
144144
final int chunksUploaded = res.data['chunksUploaded'] as int;
145-
offset = min(size - 1, chunksUploaded * CHUNK_SIZE);
145+
offset = chunksUploaded * CHUNK_SIZE;
146146
} on {{spec.title | caseUcfirst}}Exception catch (_) {}
147147
}
148148

@@ -155,7 +155,7 @@ class ClientIO extends ClientBase with ClientMixin {
155155
while (offset < size) {
156156
List<int> chunk = [];
157157
if (file.bytes != null) {
158-
final end = min(offset + CHUNK_SIZE, size - 1);
158+
final end = min(offset + CHUNK_SIZE - 1, size - 1);
159159
chunk = file.bytes!.getRange(offset, end).toList();
160160
} else {
161161
raf!.setPositionSync(offset);
@@ -164,7 +164,7 @@ class ClientIO extends ClientBase with ClientMixin {
164164
params[paramName] =
165165
http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename);
166166
headers['content-range'] =
167-
'bytes $offset-${min<int>((offset + CHUNK_SIZE), size - 1)}/$size';
167+
'bytes $offset-${min<int>((offset + CHUNK_SIZE - 1), size - 1)}/$size';
168168
res = await call(HttpMethod.post,
169169
path: path, headers: headers, params: params);
170170
offset += CHUNK_SIZE;
@@ -173,8 +173,8 @@ class ClientIO extends ClientBase with ClientMixin {
173173
}
174174
final progress = UploadProgress(
175175
$id: res.data['\$id'] ?? '',
176-
progress: min(offset + 1, size) / size * 100,
177-
sizeUploaded: min(offset + 1, size),
176+
progress: min(offset, size) / size * 100,
177+
sizeUploaded: min(offset, size),
178178
chunksTotal: res.data['chunksTotal'] ?? 0,
179179
chunksUploaded: res.data['chunksUploaded'] ?? 0,
180180
);

templates/flutter/lib/src/client_browser.dart.twig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,18 @@ class ClientBrowser extends ClientBase with ClientMixin {
143143
headers: headers,
144144
);
145145
final int chunksUploaded = res.data['chunksUploaded'] as int;
146-
offset = min(size - 1, chunksUploaded * CHUNK_SIZE);
146+
offset = chunksUploaded * CHUNK_SIZE;
147147
} on {{spec.title | caseUcfirst}}Exception catch (_) {}
148148
}
149149

150150
while (offset < size) {
151151
var chunk;
152-
final end = min(offset + CHUNK_SIZE, size - 1);
152+
final end = min(offset + CHUNK_SIZE - 1, size - 1);
153153
chunk = file.bytes!.getRange(offset, end).toList();
154154
params[paramName] =
155155
http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename);
156156
headers['content-range'] =
157-
'bytes $offset-${min<int>((offset + CHUNK_SIZE), size - 1)}/$size';
157+
'bytes $offset-${min<int>((offset + CHUNK_SIZE - 1), size - 1)}/$size';
158158
res = await call(HttpMethod.post,
159159
path: path, headers: headers, params: params);
160160
offset += CHUNK_SIZE;
@@ -163,8 +163,8 @@ class ClientBrowser extends ClientBase with ClientMixin {
163163
}
164164
final progress = UploadProgress(
165165
$id: res.data['\$id'] ?? '',
166-
progress: min(offset + 1, size) / size * 100,
167-
sizeUploaded: min(offset + 1, size),
166+
progress: min(offset, size) / size * 100,
167+
sizeUploaded: min(offset, size),
168168
chunksTotal: res.data['chunksTotal'] ?? 0,
169169
chunksUploaded: res.data['chunksUploaded'] ?? 0,
170170
);

templates/flutter/lib/src/client_io.dart.twig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class ClientIO extends ClientBase with ClientMixin {
263263
headers: headers,
264264
);
265265
final int chunksUploaded = res.data['chunksUploaded'] as int;
266-
offset = min(size - 1, chunksUploaded * CHUNK_SIZE);
266+
offset = chunksUploaded * CHUNK_SIZE;
267267
} on {{spec.title | caseUcfirst}}Exception catch (_) {}
268268
}
269269

@@ -276,7 +276,7 @@ class ClientIO extends ClientBase with ClientMixin {
276276
while (offset < size) {
277277
List<int> chunk = [];
278278
if (file.bytes != null) {
279-
final end = min(offset + CHUNK_SIZE, size - 1);
279+
final end = min(offset + CHUNK_SIZE - 1, size - 1);
280280
chunk = file.bytes!.getRange(offset, end).toList();
281281
} else {
282282
raf!.setPositionSync(offset);
@@ -285,7 +285,7 @@ class ClientIO extends ClientBase with ClientMixin {
285285
params[paramName] =
286286
http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename);
287287
headers['content-range'] =
288-
'bytes $offset-${min<int>((offset + CHUNK_SIZE), size - 1)}/$size';
288+
'bytes $offset-${min<int>((offset + CHUNK_SIZE - 1), size - 1)}/$size';
289289
res = await call(HttpMethod.post,
290290
path: path, headers: headers, params: params);
291291
offset += CHUNK_SIZE;
@@ -294,8 +294,8 @@ class ClientIO extends ClientBase with ClientMixin {
294294
}
295295
final progress = UploadProgress(
296296
$id: res.data['\$id'] ?? '',
297-
progress: min(offset + 1, size) / size * 100,
298-
sizeUploaded: min(offset + 1, size),
297+
progress: min(offset, size) / size * 100,
298+
sizeUploaded: min(offset, size),
299299
chunksTotal: res.data['chunksTotal'] ?? 0,
300300
chunksUploaded: res.data['chunksUploaded'] ?? 0,
301301
);

0 commit comments

Comments
 (0)