Skip to content

fix large object upload and and update functional test for 0 byte file upload #1396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 5 additions & 2 deletions src/internal/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ export class TypedClient {

// Inserts correct `content-type` attribute based on metaData and filePath
metaData = insertContentType(metaData || {}, filePath)
const stat = await fsp.lstat(filePath)
const stat = await fsp.stat(filePath)
return await this.putObject(bucketName, objectName, fs.createReadStream(filePath), stat.size, metaData)
}

Expand Down Expand Up @@ -1656,9 +1656,12 @@ export class TypedClient {
// Backward compatibility
size = this.maxObjectSize
}
if (size === 0) {
return this.uploadBuffer(bucketName, objectName, headers, Buffer.from(''))
}

const partSize = this.calculatePartSize(size)
if (typeof stream === 'string' || stream.readableLength === 0 || Buffer.isBuffer(stream) || size <= partSize) {
if (typeof stream === 'string' || Buffer.isBuffer(stream) || size <= partSize) {
const buf = isReadableStream(stream) ? await readAsBuffer(stream) : Buffer.from(stream)
return this.uploadBuffer(bucketName, objectName, headers, buf)
}
Expand Down
17 changes: 17 additions & 0 deletions tests/functional/functional-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,23 @@
.catch(done)
},
)

step(
`putObject(bucketName, objectName, 0byte)_bucketName:${bucketName}, objectName:${_MultiPath100kbObjectBufferName}, 0bytefile`,
(done) => {
client
.putObject(bucketName, '0bytefile', '')
.then(() => done())
.catch(done)
},
)

step(`removeObject(0byte, objectName)_bucketName:${bucketName}, objectName:0bytefile`, (done) => {
client
.removeObject(bucketName, '0bytefile')
.then(() => done())
.catch(done)
})
})
describe('tests for putObject copyObject getObject getPartialObject statObject removeObject', function () {
var tmpFileUpload = `${tmpDir}/${_100kbObjectName}`
Expand Down Expand Up @@ -3629,13 +3646,13 @@
const metadata = { 'X-Amz-Meta-Test': 'test-value' }

before(() => {
return client.makeBucket(bucketName, '').then((res) => {

Check warning on line 3649 in tests/functional/functional-tests.js

View workflow job for this annotation

GitHub Actions / lint

'res' is defined but never used
return client.putObject(bucketName, objectName, fdObject, fdObject.length, metadata).then((res) => {

Check warning on line 3650 in tests/functional/functional-tests.js

View workflow job for this annotation

GitHub Actions / lint

'res' is defined but never used
return client.setObjectTagging(bucketName, objectName, tags)
})
})
})
after(() => client.removeObject(bucketName, objectName).then((_) => client.removeBucket(bucketName)))

Check warning on line 3655 in tests/functional/functional-tests.js

View workflow job for this annotation

GitHub Actions / lint

'_' is defined but never used

step(
`extensions.listObjectsV2WithMetadata(bucketName, prefix, recursive)_bucketName:${bucketName}, prefix:"", recursive:true`,
Expand Down
Loading