Skip to content

Commit fe1f944

Browse files
committed
support SSE
1 parent 1beeed7 commit fe1f944

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

sdk/base.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ function getObject(params, callback) {
10461046
* @param {String} params.GrantRead 赋予被授权者读的权限,格式 x-cos-grant-read: uin=" ",uin=" ",非必须
10471047
* @param {String} params.GrantWrite 赋予被授权者写的权限,格式 x-cos-grant-write: uin=" ",uin=" ",非必须
10481048
* @param {String} params.GrantFullControl 赋予被授权者读写权限,格式 x-cos-grant-full-control: uin=" ",uin=" ",非必须
1049+
* @param {String} params.ServiceSideEncryption 支持按照指定的加密算法进行服务端数据加密,格式 x-cos-server-side-encryption: "AES256",非必须
10491050
* @param {Function} params.onProgress 上传进度回调函数
10501051
* @param {Function} callback 回调函数,必须
10511052
* @return {Object} err 请求失败的错误,如果请求成功,则为空。
@@ -1069,6 +1070,7 @@ function putObject(params, callback) {
10691070
headers['x-cos-grant-write'] = params['GrantWrite'];
10701071
headers['x-cos-grant-full-control'] = params['GrantFullControl'];
10711072
headers['x-cos-storage-class'] = params['StorageClass'];
1073+
headers['x-cos-server-side-encryption'] = params['ServiceSideEncryption'];
10721074

10731075
for (var key in params) {
10741076
if (key.indexOf('x-cos-meta-') > -1) {
@@ -1325,6 +1327,7 @@ function optionsObject(params, callback) {
13251327
* @param {String} ContentType RFC 2616 中定义的 HTTP 请求内容类型(MIME),例如text/plain
13261328
* @param {String} Expect 请求的特定的服务器行为
13271329
* @param {String} Expires 响应过期的日期和时间
1330+
* @param {String} params.ServiceSideEncryption 支持按照指定的加密算法进行服务端数据加密,格式 x-cos-server-side-encryption: "AES256",非必须
13281331
* @param {String} ContentLanguage 指定内容语言
13291332
* @param {String} x-cos-meta-* 允许用户自定义的头部信息,将作为 Object 元数据返回。大小限制2K。
13301333
*/
@@ -1349,6 +1352,7 @@ function putObjectCopy(params, callback) {
13491352
headers['Content-Type'] = params['ContentType'];
13501353
headers['Expect'] = params['Expect'];
13511354
headers['Expires'] = params['Expires'];
1355+
headers['x-cos-server-side-encryption'] = params['ServiceSideEncryption'];
13521356

13531357
for (var key in params) {
13541358
if (key.indexOf('x-cos-meta-') > -1) {
@@ -1476,6 +1480,7 @@ function deleteMultipleObject(params, callback) {
14761480
* @param {String} params.GrantWrite 赋予被授权者写的权限 ,非必须
14771481
* @param {String} params.GrantFullControl 赋予被授权者读写权限 ,非必须
14781482
* @param {String} params.StorageClass 设置Object的存储级别,枚举值:Standard,Standard_IA,Nearline,非必须
1483+
* @param {String} params.ServiceSideEncryption 支持按照指定的加密算法进行服务端数据加密,格式 x-cos-server-side-encryption: "AES256",非必须
14791484
* @param {Function} callback 回调函数,必须
14801485
* @return {Object} err 请求失败的错误,如果请求成功,则为空。
14811486
* @return {Object} data 返回的数据
@@ -1494,7 +1499,7 @@ function multipartInit(params, callback) {
14941499
headers['x-cos-grant-write'] = params['GrantWrite'];
14951500
headers['x-cos-grant-full-control'] = params['GrantFullControl'];
14961501
headers['x-cos-storage-class'] = params['StorageClass'];
1497-
1502+
headers['x-cos-server-side-encryption'] = params['ServiceSideEncryption'];
14981503
for (var key in params) {
14991504
if (key.indexOf('x-cos-meta-') > -1) {
15001505
headers[key] = params[key];

test/test.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ if (process.env.AppId) {
1111
SecretId: process.env.SecretId,
1212
SecretKey: process.env.SecretKey,
1313
Bucket: process.env.Bucket, // Bucket 格式:test-1250000000
14-
Region: process.env.Region,
14+
Region: process.env.Region
1515
}
1616
}
1717

1818
var cos = new COS({
1919
SecretId: config.SecretId,
20-
SecretKey: config.SecretKey,
20+
SecretKey: config.SecretKey
2121
});
2222

2323
var AppId = config.AppId;
@@ -222,7 +222,17 @@ describe('putObject()', function () {
222222
fs.unlinkSync(filepath);
223223
getObjectContent(function (objectContent) {
224224
assert.ok(objectContent === content);
225-
done();
225+
cos.putObjectCopy({
226+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
227+
Region: config.Region,
228+
//ServiceSideEncryption: 'AES256',
229+
Key: '1.copy.text',
230+
CopySource: config.Bucket + '.cos.' + config.Region + '.myqcloud.com/' + filename, // Bucket 格式:test-1250000000
231+
}, function (err, data) {
232+
assert.ok(!err);
233+
assert.ok(data.ETag.length > 0);
234+
done();
235+
});
226236
});
227237
});
228238
});
@@ -303,7 +313,14 @@ describe('getObject()', function () {
303313
objectContent = objectContent.toString();
304314
assert.ok(data.headers['content-length'] === '' + content.length);
305315
assert.ok(objectContent === content);
306-
done();
316+
cos.headObject({
317+
Bucket: config.Bucket,
318+
Region: config.Region,
319+
Key: key
320+
}, function (err, data) {
321+
assert.ok(!err);
322+
done();
323+
});
307324
});
308325
}, 2000);
309326
});

0 commit comments

Comments
 (0)