diff --git a/README.md b/README.md index 5ff24d2de..28a9bcc6b 100644 --- a/README.md +++ b/README.md @@ -1525,8 +1525,8 @@ parameters: - [parallel] {Number} the number of parts to be uploaded in parallel - [partSize] {Number} the suggested size for each part - [progress] {Function} the progress callback called after each - successful upload of one part, it will be given two parameters: - (percentage {Number}, checkpoint {Object}) + successful upload of one part, it will be given three parameters: + (percentage {Number}, checkpoint {Object}, res {Object}) - [checkpoint] {Object} the checkpoint to resume upload, if this is provided, it will continue the upload from where interrupted, otherwise a new multipart upload will be created. @@ -1559,17 +1559,19 @@ console.log(result); var result = yield store.multipartUpload('object', '/tmp/file', { parallel: 4, partSize: 1024 * 1024, - progress: function* (p, cpt) { + progress: function* (p, cpt, res) { console.log(p); console.log(cpt); + console.log(res.headers['x-oss-request-id']); } }); var result = yield store.multipartUpload('object', '/tmp/file', { checkpoint: savedCpt, - progress: function* (p, cpt) { + progress: function* (p, cpt, res) { console.log(p); console.log(cpt); + console.log(res.headers['x-oss-request-id']); } }); diff --git a/lib/browser/multipart.js b/lib/browser/multipart.js index ee5fd5267..e5ed3724f 100644 --- a/lib/browser/multipart.js +++ b/lib/browser/multipart.js @@ -73,6 +73,11 @@ proto.multipartUpload = function* multipartUpload(name, file, options) { doneParts: [] }; + if (options && options.progress) { + yield options.progress(0, checkpoint, result.res); + } + + return yield this._resumeMultipart(checkpoint, options); }; @@ -108,7 +113,7 @@ proto._resumeMultipart = function* _resumeMultipart(checkpoint, options) { checkpoint.doneParts = doneParts; if (options && options.progress) { - yield options.progress(doneParts.length / numParts, checkpoint); + yield options.progress(doneParts.length / numParts, checkpoint, result.res); } }; diff --git a/lib/browser/version.js b/lib/browser/version.js index 79c4b15d0..b7d059476 100644 --- a/lib/browser/version.js +++ b/lib/browser/version.js @@ -1 +1 @@ -exports.version="4.11.2" \ No newline at end of file +exports.version="4.11.3" \ No newline at end of file diff --git a/lib/multipart.js b/lib/multipart.js index fc6b10f8a..927a8c152 100644 --- a/lib/multipart.js +++ b/lib/multipart.js @@ -73,6 +73,10 @@ proto.multipartUpload = function* multipartUpload(name, file, options) { doneParts: [] }; + if (options && options.progress) { + yield options.progress(0, checkpoint, result.res); + } + return yield this._resumeMultipart(checkpoint, options); }; @@ -108,7 +112,7 @@ proto._resumeMultipart = function* _resumeMultipart(checkpoint, options) { checkpoint.doneParts = doneParts; if (options && options.progress) { - yield options.progress(doneParts.length / numParts, checkpoint); + yield options.progress(doneParts.length / numParts, checkpoint, result.res); } }; diff --git a/test/browser.tests.js b/test/browser.tests.js index 11f258b34..adb901964 100644 --- a/test/browser.tests.js +++ b/test/browser.tests.js @@ -20,11 +20,11 @@ timemachine.reset(); describe('browser', function () { before(function* () { ossConfig = { - region: stsConfig.region, - accessKeyId: stsConfig.Credentials.AccessKeyId, - accessKeySecret: stsConfig.Credentials.AccessKeySecret, - stsToken: stsConfig.Credentials.SecurityToken, - bucket: stsConfig.bucket + region: stsConfig.region, + accessKeyId: stsConfig.Credentials.AccessKeyId, + accessKeySecret: stsConfig.Credentials.AccessKeySecret, + stsToken: stsConfig.Credentials.SecurityToken, + bucket: stsConfig.bucket }; // this.store = oss({ // region: stsConfig.region, @@ -423,7 +423,7 @@ describe('browser', function () { result.objects.map(checkObjectProperties); assert.equal(result.nextMarker, null); assert(!result.isTruncated); - assert.deepEqual(result.prefixes, [ this.listPrefix + 'fun/', this.listPrefix + 'other/' ]); + assert.deepEqual(result.prefixes, [this.listPrefix + 'fun/', this.listPrefix + 'other/']); var result = yield this.store.list({ prefix: this.listPrefix + 'fun/', @@ -447,7 +447,7 @@ describe('browser', function () { }); }); - describe('put', function() { + describe('put', function () { before(function* () { this.store = oss(ossConfig); }); @@ -531,7 +531,7 @@ describe('browser', function () { assert.equal(urlRes.data.toString(), result.content.toString()); }); - it('should signature url with custom host ok', function() { + it('should signature url with custom host ok', function () { var store = oss(Object.assign({}, ossConfig, { endpoint: 'www.aliyun.com', cname: true @@ -543,7 +543,7 @@ describe('browser', function () { }); }); - describe('multipart', function() { + describe('multipart', function () { before(function* () { this.store = oss(ossConfig); }); @@ -727,7 +727,7 @@ describe('browser', function () { it('should upload file using multipart upload', function* () { // create a file with 1M random data // var fileName = yield utils.createTempFile('multipart-upload-file', 1024 * 1024); - var fileContent = Array(1024*1024).fill('a').join('') + var fileContent = Array(1024 * 1024).fill('a').join('') var file = new File([fileContent], 'multipart-fallback'); var name = prefix + 'multipart/upload-file.js'; @@ -743,14 +743,14 @@ describe('browser', function () { }); sinon.restore(); assert.equal(result.res.status, 200); - assert.equal(progress, 11); + assert.equal(progress, 12); var object = yield this.store.get(name); assert.equal(object.res.status, 200); - var fileBuf=new Uint8Array(fileContent.length); - for(var i=0,j=fileContent.length;i { before(function* () { this.store = OSS(config); - this.bucket = 'ali-oss-test-object-bucket-' + prefix.replace(/[\/\.]/g, '-'); + this.bucket = 'ali-oss-test-wrapper-bucket-' + prefix.replace(/[\/\.]/g, '-'); this.bucket = this.bucket.substring(0, this.bucket.length - 1); this.region = config.region; @@ -76,7 +76,7 @@ describe('test/wrapper.test.js', () => { } }).then(function (val) { assert.equal(val.res.status, 200); - assert.equal(count, Math.ceil(1024 / 100)); + assert.equal(count, 12); return store.get(name); }).then(function (val) {