Skip to content

Commit 952f64b

Browse files
authored
fix(storage): multipart upload is firing on 0 bytes data (#13927)
1 parent caad557 commit 952f64b

File tree

2 files changed

+17
-1
lines changed
  • packages/storage

2 files changed

+17
-1
lines changed

packages/storage/__tests__/providers/s3/apis/uploadData/index.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,22 @@ describe('uploadData with path', () => {
180180
},
181181
);
182182

183+
it('should use putObject for 0 bytes data (e.g. create a folder)', () => {
184+
const testInput = {
185+
path: 'test-path',
186+
data: '', // 0 bytes
187+
};
188+
189+
uploadData(testInput);
190+
191+
expect(mockPutObjectJob).toHaveBeenCalledWith(
192+
testInput,
193+
expect.any(AbortSignal),
194+
expect.any(Number),
195+
);
196+
expect(mockGetMultipartUploadHandlers).not.toHaveBeenCalled();
197+
});
198+
183199
it('should use uploadTask', async () => {
184200
mockPutObjectJob.mockReturnValueOnce('putObjectJob');
185201
mockCreateUploadTask.mockReturnValueOnce('uploadTask');

packages/storage/src/providers/s3/apis/uploadData/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export function uploadData(input: UploadDataInput | UploadDataWithPathInput) {
135135
StorageValidationErrorCode.ObjectIsTooLarge,
136136
);
137137

138-
if (dataByteLength && dataByteLength <= DEFAULT_PART_SIZE) {
138+
if (dataByteLength !== undefined && dataByteLength <= DEFAULT_PART_SIZE) {
139139
// Single part upload
140140
const abortController = new AbortController();
141141

0 commit comments

Comments
 (0)