From ceae401c3dd3d9e1f64fef172bcf42a291402dc6 Mon Sep 17 00:00:00 2001 From: JingDan Date: Mon, 8 Jan 2018 12:53:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=89=87=E4=B8=8A=E4=BC=A0=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0init=20upload=20part,complete3=E4=B8=AA=E6=83=85?= =?UTF-8?q?=E5=86=B5=E7=9A=84=20requestId=20(#335)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加 分片上传返回request id 初始化和 单片上传 * add requestid with multipart and test case * fix test ase * opti: test case assert * fix node test case * add multipart doc * opti: test case * case 判空 * fix test case * fix test case --- README.md | 10 +++++---- lib/browser/multipart.js | 7 +++++- lib/browser/version.js | 2 +- lib/multipart.js | 6 ++++- test/browser.tests.js | 47 +++++++++++++++++++++++++++------------- test/multipart.test.js | 20 +++++++++++++++-- test/wrapper.test.js | 4 ++-- 7 files changed, 70 insertions(+), 26 deletions(-) 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) {