Skip to content

Commit

Permalink
update csp doc
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Nov 5, 2018
1 parent 198bb79 commit cd1ad63
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 249 deletions.
207 changes: 4 additions & 203 deletions csp/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -898,47 +898,7 @@ Put Bucket Lifecycle 接口可以设置存储桶的生命周期规则。

#### 使用示例

示例一:上传 30 天后,沉降至低频存储
```js
cos.putBucketLifecycle({
Bucket: 'test-1250000000', /* 必须 */
Region: 'ap-guangzhou', /* 必须 */
Rules: [{
"ID": "1",
"Status": "Enabled",
"Filter": {},
"Transition": {
"Days": "30",
"StorageClass": "STANDARD_IA"
}
}],
}, function(err, data) {
console.log(err || data);
});
```

示例二:指定目录前缀 dir/,上传 90 天后,沉降至归档存储
```js
cos.putBucketLifecycle({
Bucket: 'test-1250000000', /* 必须 */
Region: 'ap-guangzhou', /* 必须 */
Rules: [{
"ID": "2",
"Filter": {
"Prefix": "dir/",
},
"Status": "Enabled",
"Transition": {
"Days": "90",
"StorageClass": "ARCHIVE"
}
}],
}, function(err, data) {
console.log(err || data);
});
```

示例三:上传 180 天后,删除文件
示例一:上传 180 天后,删除文件
```js
cos.putBucketLifecycle({
Bucket: 'test-1250000000', /* 必须 */
Expand All @@ -956,7 +916,7 @@ cos.putBucketLifecycle({
});
```

示例四:上传 30 天后,删除碎片
示例二:上传 30 天后,删除碎片(未完成的UploadId)
```js
cos.putBucketLifecycle({
Bucket: 'test-1250000000', /* 必须 */
Expand Down Expand Up @@ -988,6 +948,8 @@ cos.putBucketLifecycle({
| - - - Prefix | 规则要匹配上的 Object 前缀 | String ||
| - - Expiration | 表示对 Object 删除 | Object ||
| - - - Days | 规则生效天数,按文件上传时间开始算,必须为正整数 | Object ||
| - - AbortIncompleteMultipartUpload | 表示删除碎片 | Object ||
| - - - Days | 规则生效天数,按文件上传时间开始算,必须为正整数 | Object ||

#### 回调函数说明

Expand Down Expand Up @@ -1045,167 +1007,6 @@ function(err, data) { ... }
| - headers | 请求返回的头部信息 | Object |


### Get Bucket Replication

Get Bucket Replication 接口实现获取存储桶的跨区域复制规则

#### 使用示例

```js
cos.getBucketReplication({
Bucket: 'test-1250000000', /* 必须 */
Region: 'ap-guangzhou', /* 必须 */
}, function(err, data) {
console.log(err || data);
});
```

#### 返回示例

```json
{
"ReplicationConfiguration": {
"Role": "qcs::cam::uin/459000000:uin/459000000",
"Rules": {
"ID": "1",
"Status": "Enabled",
"Prefix": "sync/",
"Destination": {
"Bucket": "qcs:id/0:cos:ap-chengdu:appid/1250000000:backup",
"StorageClass": "Standard"
}
}
},
"statusCode": 200,
"headers": {}
}
```

#### 参数说明

| 参数名 | 参数描述 | 类型 | 必填 |
|--------|----------|------|------|
| Bucket | Bucket 的名称。命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 | String ||
| Region | Bucket 所在区域。枚举值请见:[Bucket 地域信息](https://cloud.tencent.com/document/product/436/6224) | String ||

#### 回调函数说明

```js
function(err, data) { ... }
```

| 参数名 | 参数描述 | 类型 |
|--------|----------|------|
| err | 请求发生错误时返回的对象,包括网络错误和业务错误。如果请求成功,则为空,[错误码文档](https://cloud.tencent.com/document/product/436/7730) | Object |
| data | 请求成功时返回的对象,如果请求发生错误,则为空 | Object |
| - ReplicationConfiguration | 跨区域复制规则 | Object |
| - - Role | 复制过程以什么角色的身份,格式:qcs::cam::uin/10001:uin/10002,其中 10001 是主帐号,10002 是子帐号 | Object |
| - - Rules | 复制具体规则列表 | ObjectArray |
| - - - ID | 任务标识 ID | String |
| - - - Status | 规则状态,枚举值:Enabled、Disabled | String |
| - - - Prefix | 要复制的 Object 前缀 | String |
| - - - Destination | 要复制的 Object 前缀 | Object |
| - - - - Bucket | 要复制到的存储桶,格式:qcs:id/0:cos:<Region>:appid/<AppId>:<ShortBucketName>,例如:qcs:id/0:cos:ap-guangzhou:appid/1250000000:backup | Object |
| - - - - StorageClass | 复制后的存储类型,枚举值:STANDARD、STANDARD_IA,默认值:STANDARD | Object |


### Put Bucket Replication

Put Bucket Replication 接口实现设置存储桶的跨区域复制规则。

#### 使用示例

```js
cos.putBucketReplication({
Bucket: 'test-1250000000', /* 必须 */
Region: 'ap-guangzhou', /* 必须 */
ReplicationConfiguration: { /* 必须 */
Role: "qcs::cam::uin/459000000:uin/459000000",
Rules: [{
ID: "1",
Status: "Enabled",
Prefix: "sync/",
Destination: {
Bucket: "qcs:id/0:cos:ap-chengdu:appid/1250000000:backup",
StorageClass: "Standard",
}
}]
}
}, function (err, data) {
console.log(err || data);
});
```

#### 参数说明

| 参数名 | 参数描述 | 类型 | 必填 |
|--------|----------|------|------|
| Bucket | Bucket 的名称。命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 | String ||
| Region | Bucket 所在区域。枚举值请见:[Bucket 地域信息](https://cloud.tencent.com/document/product/436/6224) | String ||
| ReplicationConfiguration | 定义跨区域复制规则 | Object ||
| - Role | 复制过程以什么角色的身份,格式:qcs::cam::uin/10001:uin/10002,其中 10001 是主帐号,10002 是子帐号 | Object ||
| - Rules | 复制具体规则列表 | ObjectArray ||
| - - ID | 任务标识 ID | String ||
| - - Status | 规则状态,枚举值:Enabled、Disabled | String ||
| - - Prefix | 要复制的 Object 前缀 | String ||
| - - Destination | 要复制的 Object 前缀 | Object ||
| - - - Bucket | 要复制到的存储桶,格式:qcs:id/0:cos:<Region>:appid/<AppId>:<ShortBucketName>,例如:qcs:id/0:cos:ap-guangzhou:appid/1250000000:backup | Object ||
| - - - StorageClass | 复制后的存储类型,枚举值:STANDARD、STANDARD_IA,默认值:STANDARD | Object ||

#### 回调函数说明

```js
function(err, data) { ... }
```

| 参数名 | 参数描述 | 类型 |
|--------|----------|------|
| err | 请求发生错误时返回的对象,包括网络错误和业务错误。如果请求成功,则为空,[错误码文档](https://cloud.tencent.com/document/product/436/7730) | Object |
| - statusCode | 请求返回的 HTTP 状态码,如 200、403、404 等 | Number |
| - headers | 请求返回的头部信息 | Object |
| data | 请求成功时返回的对象,如果请求发生错误,则为空 | Object |
| - statusCode | 请求返回的 HTTP 状态码,如 200、403、404 等 | Number |
| - headers | 请求返回的头部信息 | Object |


### Delete Bucket Replication

Delete Bucket Replication 接口可以删除存储桶的跨区域复制规则。

#### 使用示例

```js
cos.deleteBucketReplication({
Bucket: 'test-1250000000', /* 必须 */
Region: 'ap-guangzhou', /* 必须 */
}, function(err, data) {
console.log(err || data);
});
```

#### 参数说明

| 参数名 | 参数描述 | 类型 | 必填 |
|--------|----------|------|------|
| Bucket | Bucket 的名称。命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 | String ||
| Region | Bucket 所在区域。枚举值请见:[Bucket 地域信息](https://cloud.tencent.com/document/product/436/6224) | String ||

#### 回调函数说明

```js
function(err, data) { ... }
```

| 参数名 | 参数描述 | 类型 |
|--------|----------|------|
| err | 请求发生错误时返回的对象,包括网络错误和业务错误。如果请求成功,则为空,[错误码文档](https://cloud.tencent.com/document/product/436/7730) | Object |
| - statusCode | 请求返回的 HTTP 状态码,如 200、403、404 等 | Number |
| - headers | 请求返回的头部信息 | Object |
| data | 请求成功时返回的对象,如果请求发生错误,则为空 | Object |
| - statusCode | 请求返回的 HTTP 状态码,如 200、403、404 等 | Number |
| - headers | 请求返回的头部信息 | Object |



## Object 操作

Expand Down
4 changes: 3 additions & 1 deletion csp/auth.php → csp/auth-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,6 @@ function obj2str($obj)
header('Content-Type: text/plain');
header('Allow-Control-Allow-Origin: http://127.0.0.1'); // 这里修改允许跨域访问的网站
header('Allow-Control-Allow-Headers: origin,accept,content-type');
echo getAuthorization($method, $pathname, $query, $headers);
$sign = getAuthorization($method, $pathname, $query, $headers);

echo '{"sign":"' . $sign .'"}';
57 changes: 12 additions & 45 deletions csp/csp.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,24 @@ <h1>cos-js-sdk-v5</h1>
var cos = new COS({
CompatibilityMode: true,
ServiceDomain: 'http://cos.default.example.com',

// 后缀式
Domain: 'http://cos.{Region}.example.com', // 后缀式
ForcePathStyle: true, // 后缀式

// 前缀式
// Domain: 'http://{Bucket}.cos.{Region}.example.com', // 前缀式

getAuthorization: function (options, callback) {
var url = './auth.php?method=' + options.Method + '&pathname=' + encodeURIComponent(options.Key);
var url = './auth-json.php?method=' + options.Method + '&pathname=' + encodeURIComponent(options.Key);
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onload = function (e) {
callback(e.target.responseText);
var sign;
try {
sign = JSON.parse(e.target.responseText).sign;
} catch (e) {}
callback(sign);
};
xhr.send();
},
Expand Down Expand Up @@ -92,7 +101,7 @@ <h1>cos-js-sdk-v5</h1>

function getAuth() {
var key = '1.png';
getAuthorization({
cos.options.getAuthorization({
Method: 'get',
Key: key
}, function (auth) {
Expand Down Expand Up @@ -270,45 +279,6 @@ <h1>cos-js-sdk-v5</h1>
});
}

function putBucketReplication() {
var AppId = config.Bucket.substr(config.Bucket.lastIndexOf('-') + 1);
cos.putBucketReplication({
Bucket: config.Bucket, // Bucket 格式:test-1250000000
Region: config.Region,
ReplicationConfiguration: {
Role: "qcs::cam::uin/459000000:uin/459000000",
Rules: [{
ID: "1",
Status: "Enabled",
Prefix: "img/",
Destination: {
Bucket: "qcs::cos:ap-guangzhou::test-" + AppId
},
}]
}
}, function (err, data) {
logger.log(err || data);
});
}

function getBucketReplication() {
cos.getBucketReplication({
Bucket: config.Bucket, // Bucket 格式:test-1250000000
Region: config.Region
}, function (err, data) {
logger.log(err || data);
});
}

function deleteBucketReplication() {
cos.deleteBucketReplication({
Bucket: config.Bucket, // Bucket 格式:test-1250000000
Region: config.Region
}, function (err, data) {
logger.log(err || data);
});
}

function deleteBucket() {
cos.deleteBucket({
Bucket: 'testnew-' + config.Bucket.substr(config.Bucket.lastIndexOf('-') + 1),
Expand Down Expand Up @@ -654,9 +624,6 @@ <h1>cos-js-sdk-v5</h1>
'getBucketLifecycle',
'putBucketLifecycle',
'deleteBucketLifecycle',
'putBucketReplication',
'getBucketReplication',
'deleteBucketReplication',
'deleteBucket',
'putObject',
'putObjectCopy',
Expand Down

0 comments on commit cd1ad63

Please sign in to comment.