UNPKG

ks3-js-sdk

Version:

js sdk for ks3

123 lines 4.89 kB
var copyMultipart = function () { describe('分块拷贝文件', function () { let key = 'demo-copy.pdf'; let sourceBucket = 'zwy-test'; let sourceKey = '57M.pdf'; let file = blob({ size: 1024 * 1024 * 5 }); before('上传文件,并通过请求头设置用户自定义元数据', function (done) { this.timeout(10000); ks3.putObject({ key: sourceKey, file, bucket: sourceBucket, headers: { 'x-kss-meta-info': 'abc' } }).then(res => { should.not.exist(res.error); res.statusCode.should.be.equal(200); done() }) }) after('删除文件', function (done) { this.timeout(2000); ks3.delObject({ key, }).then(res => { should.not.exist(res.error); res.statusCode.should.be.equal(204); done() }) }) describe('拷贝文件', function () { it('uploadPartCopy方法拷贝文件', function (done) { this.timeout(5000); ks3.uploadPartCopy({ key, sourceKey, sourceBucket }, function(res){ should.not.exist(res.error); res.statusCode.should.be.equal(200); done(); }) }) it('获取拷贝文件的信息和存储类型', function (done) { this.timeout(2000); ks3.listObjects({ prefix: key }).then(res => { let contents = res.body.ListBucketResult.Contents; let object; if (contents instanceof Array) { object = contents.find((item) => item.Key === key); } else { object = contents; } object.StorageClass.should.be.equal('STANDARD'); object.Size.should.be.equal(file.size.toString()); should.not.exist(res.error); res.statusCode.should.be.equal(200); done(); }) }) // it('删除拷贝的文件', function (done) { // this.timeout(2000); // ks3.delObject({ // key: key // }).then(res => { // should.not.exist(res.error); // res.statusCode.should.be.equal(204); // done(); // }) // }) }) //分块拷贝不只是设定与源文件不符的存储类型 // describe('拷贝文件,并通过请求头设置存储类型为STANDARD_IA', function () { // it('请求头中的x-kss-storage-class值为STANDARD_IA', function (done) { // this.timeout(5000); // ks3.uploadPartCopy({ // key, // sourceKey, // sourceBucket, // headers: { // 'x-kss-storage-class': 'STANDARD_IA' // } // },function(res){ // should.not.exist(res.error); // res.statusCode.should.be.equal(200); // done(); // }) // }) // it('获取拷贝文件的信息和存储类型', function (done) { // this.timeout(2000); // ks3.listObjects({ // prefix: key // }).then(res => { // let contents = res.body.ListBucketResult.Contents; // let object; // if (contents instanceof Array) { // object = contents.find((item) => item.Key === key); // } else { // object = contents; // } // object.StorageClass.should.be.equal('STANDARD_IA'); // object.Size.should.be.equal(file.size.toString()); // should.not.exist(res.error); // res.statusCode.should.be.equal(200); // done(); // }) // }) // it('删除拷贝的文件', function (done) { // this.timeout(2000); // ks3.delObject({ // key: key // }).then(res => { // should.not.exist(res.error); // res.statusCode.should.be.equal(204); // done(); // }) // }) // }) }) }