Skip to content

Commit

Permalink
fix: multipart upload from stream with metadata (#956)
Browse files Browse the repository at this point in the history
* Pass metadata only with non-multipart uploads or when initializing multipart upload

* Add metadata to multipart upload functional tests
  • Loading branch information
petslane authored Aug 13, 2021
1 parent 8969396 commit 206042f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/main/object-uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class ObjectUploader extends Transform {
_transform(chunk, encoding, callback) {
this.emptyStream = false
let method = 'PUT'
let headers = Object.assign({}, this.metaData, {'Content-Length': chunk.length})
let headers = {'Content-Length': chunk.length}
let md5digest = ''

// Calculate and set Content-MD5 header if SHA256 is not set.
Expand All @@ -75,7 +75,9 @@ export default class ObjectUploader extends Transform {
if (this.partNumber == 1 && chunk.length < this.partSize) {
// PUT the chunk in a single request — use an empty query.
let options = {
method, headers,
method,
// Set user metadata as this is not a multipart upload
headers: Object.assign({}, this.metaData, headers),
query: '',
bucketName: this.bucketName,
objectName: this.objectName
Expand Down
8 changes: 6 additions & 2 deletions src/test/functional/functional-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ describe('functional tests', function() {
.catch(done)
})

step(`putObject(bucketName, objectName, stream, cb)_bucketName:${bucketName}, objectName:${_65mbObjectName}_`, done => {
step(`putObject(bucketName, objectName, stream, metadata, cb)_bucketName:${bucketName}, objectName:${_65mbObjectName}_`, done => {
var stream = readableStream(_65mb)
client.putObject(bucketName, _65mbObjectName, stream, () => {
client.putObject(bucketName, _65mbObjectName, stream, metaData, () => {
setTimeout(() => {
if (Object.values(httpAgent.sockets).length === 0) return done()
done(new Error('http request did not release network socket'))
Expand Down Expand Up @@ -471,6 +471,10 @@ describe('functional tests', function() {
client.statObject(bucketName, _65mbObjectName, (e, stat) => {
if (e) return done(e)
if (stat.size !== _65mb.length) return done(new Error('size mismatch'))
if (`${metaData.randomstuff}` !== stat.metaData.randomstuff) return done(new Error('metadata "randomstuff" mismatch'))
if (`${metaData["X-Amz-Meta-Testing"]}` !== stat.metaData["testing"]) return done(new Error('metadata "testing" mismatch'))
if (`${metaData["Content-Type"]}` !== stat.metaData["content-type"]) return done(new Error('metadata "content-type" mismatch'))
if (`${metaData["Content-Language"]}` !== stat.metaData["content-language"]) return done(new Error('metadata "content-language" mismatch'))
done()
})
})
Expand Down

0 comments on commit 206042f

Please sign in to comment.