diff --git a/src/services/upload-strategy.ts b/src/services/upload-strategy.ts index 8969086..5273812 100644 --- a/src/services/upload-strategy.ts +++ b/src/services/upload-strategy.ts @@ -59,7 +59,7 @@ export const uploadChunkedFile = async ( const initResponse = await FileService.initChunkUpload({ file_name: file.name, file_size: file.size, - chunk_size: CHUNK_SIZE, + chunk_size: Math.min(CHUNK_SIZE, file.size), file_hash: fileHash }) diff --git a/tests/uploadStrategy.integration.test.mjs b/tests/uploadStrategy.integration.test.mjs index 29d5c45..0c4ad87 100644 --- a/tests/uploadStrategy.integration.test.mjs +++ b/tests/uploadStrategy.integration.test.mjs @@ -22,3 +22,9 @@ test('manual retry after lost completion response reuses upload id and never ret assert.equal(result.detail.code,'ORIGINAL');assert.equal(inits,1);assert.equal(chunks,1);assert.equal(completions,5) }finally{service.initChunkUpload=originals.init;service.uploadChunk=originals.chunk;service.completeChunkUpload=originals.complete;globalThis.window=previousWindow} }) +test('small file initialization never requests a chunk bigger than the file',async()=>{ + const originalInit=service.initChunkUpload;let size + const previousWindow=globalThis.window;globalThis.window={isSecureContext:true} + service.initChunkUpload=async request=>{size=request.chunk_size;return {code:200,detail:{existed:true,code:'existing'}}} + try{await upload(new File(['small'],'a.txt'),{expireValue:1,expireStyle:'day'});assert.equal(size,5)}finally{service.initChunkUpload=originalInit;globalThis.window=previousWindow} +})