Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/lib-storage/src/Upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,23 @@ describe(Upload.name, () => {
}).toThrow(`The byte size for part number 1, size 0 does not match expected size ${MOCK_PART_SIZE}`);
});

it("should use the user-specified partSize when provided, taking precedence over calculated partSize", () => {
const bigBuffer = Buffer.alloc(10);
const customPartSize = 50 * 1024 * 1024; // 50 MB

const upload = new Upload({
params: {
Key: "big-file",
Bucket: "bucket",
Body: bigBuffer,
},
partSize: customPartSize,
client: new S3({}),
});

expect((upload as any).partSize).toBe(customPartSize);
});

it("should skip validation for single-part uploads", () => {
const upload = new Upload({
params,
Expand Down
3 changes: 2 additions & 1 deletion lib/lib-storage/src/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export class Upload extends EventEmitter {
this.bytesUploadedSoFar = 0;
this.abortController = options.abortController ?? new AbortController();

this.partSize = Math.max(Upload.MIN_PART_SIZE, Math.floor((this.totalBytes || 0) / this.MAX_PARTS));
this.partSize =
options.partSize || Math.max(Upload.MIN_PART_SIZE, Math.floor((this.totalBytes || 0) / this.MAX_PARTS));
this.expectedPartsCount = this.totalBytes !== undefined ? Math.ceil(this.totalBytes / this.partSize) : undefined;

this.__validateInput();
Expand Down
Loading