Skip to content
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

Fix multipart upload from stream with metadata #956

Merged
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
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