Skip to content

Commit 13d4c84

Browse files
optlsndnd0ut
andauthored
fix(upload-client/multipart): set custom chunk size for multipart (#531)
* fix(upload-client/multipart): set custom chunk size when starting multipart upload If a multipart upload is started with a custom part size, the part size must be set in the request to `/multipart/start/` via `part_size`. Otherwise, the default 5 MB part size is used, which causes the subsequent request to `/multipart/complete/` to fail with the following error: ``` { "error": { "status_code": 400, "content": "Can not complete upload. Wrong parts size?", "error_code": "MultipartFileCompletionFailedError" } } ``` * test: add test for multipartChunkSize --------- Co-authored-by: nd0ut <[email protected]>
1 parent 89191cd commit 13d4c84

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/upload-client/src/uploadFile/uploadMultipart.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ export const uploadMultipart = async (
143143
userAgent,
144144
retryThrottledRequestMaxTimes,
145145
retryNetworkErrorMaxTimes,
146-
metadata
146+
metadata,
147+
multipartChunkSize
147148
})
148149
.then(async ({ uuid, parts }) => {
149150
const getChunk = await prepareChunks(file, size, multipartChunkSize)

packages/upload-client/test/uploadFile/uploadMultipart.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ describe('uploadMultipart', () => {
1919
expect(file.cdnUrl).toBeTruthy()
2020
})
2121

22+
it('should accept multipartChunkSize option', async () => {
23+
const file = await uploadMultipart(fileToUpload, {
24+
...settings,
25+
multipartChunkSize: 10 * 1024 * 1024
26+
})
27+
28+
expect(file.cdnUrl).toBeTruthy()
29+
})
30+
2231
it('should accept store setting', async () => {
2332
const settings = getSettingsForTesting({
2433
publicKey: factory.publicKey('image'),

0 commit comments

Comments
 (0)