Skip to content

Commit 26b4f06

Browse files
committed
Fix node chunked upload
1 parent 0cc40b9 commit 26b4f06

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

templates/node/base/requests/file.twig

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
}
4141

4242
const start = currentChunkStart;
43-
const end = Math.min(((start + client.CHUNK_SIZE) - 1), size - 1);
43+
const end = currentChunkStart + currentChunkSize - 1;
4444

4545
if(!lastUpload || currentChunkStart !== 0) {
4646
apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
@@ -50,8 +50,12 @@
5050
apiHeaders['x-{{spec.title | caseLower }}-id'] = id;
5151
}
5252

53-
const stream = Stream.Readable.from(currentChunk);
54-
payload['{{ parameter.name }}'] = { type: 'file', file: stream, filename: {{ parameter.name }}.filename };
53+
payload['{{ parameter.name }}'] = {
54+
type: 'file',
55+
file: currentChunk,
56+
filename: {{ parameter.name }}.filename,
57+
size: currentChunkSize
58+
};
5559

5660
response = await selfClient.call('{{ method.method | caseLower }}', apiPath, apiHeaders, payload{% if method.type == 'location' %}, 'arraybuffer'{% endif %});
5761

@@ -92,6 +96,7 @@
9296
if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
9397
// Upload chunk
9498
currentChunk = Buffer.concat([currentChunk, chunk]);
99+
currentChunkSize = Buffer.byteLength(currentChunk);
95100
await uploadChunk();
96101
currentChunk = Buffer.from('');
97102
currentChunkSize = 0;

0 commit comments

Comments
 (0)