Skip to content

Commit cdca218

Browse files
authored
补充完成PHP SDK缺失的对象标签功能 (#195)
* 添加对象标签删除功能 * 补充对象标签设置查询删除功能 * contentMd5仅支持boolean * 更新UT
1 parent e67ad81 commit cdca218

File tree

5 files changed

+374
-2
lines changed

5 files changed

+374
-2
lines changed

sample/deleteObjectTagging.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
require dirname(__FILE__) . '/../vendor/autoload.php';
4+
5+
$secretId = "COS_SECRETID"; //"云 API 密钥 SecretId";
6+
$secretKey = "COS_SECRETKEY"; //"云 API 密钥 SecretKey";
7+
$region = "ap-beijing"; //设置一个默认的存储桶地域
8+
$cosClient = new Qcloud\Cos\Client(
9+
array(
10+
'region' => $region,
11+
'schema' => 'https', //协议头部,默认为http
12+
'credentials'=> array(
13+
'secretId' => $secretId ,
14+
'secretKey' => $secretKey)));
15+
try {
16+
$result = $cosClient->deleteObjectTagging(array(
17+
'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID
18+
'Key' => 'exampleobject',
19+
));
20+
// 请求成功
21+
print_r($result);
22+
} catch (\Exception $e) {
23+
// 请求失败
24+
echo($e);
25+
}

sample/getObjectTagging.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
require dirname(__FILE__) . '/../vendor/autoload.php';
3+
4+
$secretId = "COS_SECRETID"; //"云 API 密钥 SecretId";
5+
$secretKey = "COS_SECRETKEY"; //"云 API 密钥 SecretKey";
6+
$region = "ap-beijing"; //设置一个默认的存储桶地域
7+
$cosClient = new Qcloud\Cos\Client(
8+
array(
9+
'region' => $region,
10+
'schema' => 'https', //协议头部,默认为http
11+
'credentials' => array(
12+
'secretId' => $secretId,
13+
'secretKey' => $secretKey)));
14+
try {
15+
$result = $cosClient->getObjectTagging(array(
16+
'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID
17+
'Key' => 'exampleobject'
18+
));
19+
// 请求成功
20+
print_r($result);
21+
} catch (\Exception $e) {
22+
// 请求失败
23+
echo($e);
24+
}
25+

sample/putObjectTagging.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
require dirname(__FILE__) . '/../vendor/autoload.php';
4+
5+
$secretId = "COS_SECRETID"; //"云 API 密钥 SecretId";
6+
$secretKey = "COS_SECRETKEY"; //"云 API 密钥 SecretKey";
7+
$region = "ap-beijing"; //设置一个默认的存储桶地域
8+
$cosClient = new Qcloud\Cos\Client(
9+
array(
10+
'region' => $region,
11+
'schema' => 'https', //协议头部,默认为http
12+
'credentials'=> array(
13+
'secretId' => $secretId ,
14+
'secretKey' => $secretKey)));
15+
try {
16+
$result = $cosClient->putObjectTagging(array(
17+
'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID
18+
'Key' => 'exampleobject',
19+
'TagSet' => array(
20+
array('Key'=>'key1',
21+
'Value'=>'value1',
22+
),
23+
array('Key'=>'key2',
24+
'Value'=>'value2',
25+
),
26+
),
27+
));
28+
// 请求成功
29+
print_r($result);
30+
} catch (\Exception $e) {
31+
// 请求失败
32+
echo "$e\n";
33+
}

src/Qcloud/Cos/Service.php

Lines changed: 149 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,104 @@ public static function getService() {
637637
),
638638
),
639639
),
640+
// 配置对象标签的方法.
641+
'PutObjectTagging' => array(
642+
'httpMethod' => 'PUT',
643+
'uri' => '/{Bucket}{/Key*}?tagging',
644+
'class' => 'Qcloud\\Cos\\Command',
645+
'responseClass' => 'PutObjectTaggingOutput',
646+
'responseType' => 'model',
647+
'data' => array(
648+
'xmlRoot' => array(
649+
'name' => 'Tagging',
650+
),
651+
'contentMd5' => true,
652+
),
653+
'parameters' => array(
654+
'Bucket' => array(
655+
'required' => true,
656+
'type' => 'string',
657+
'location' => 'uri',
658+
),
659+
'Key' => array(
660+
'required' => true,
661+
'type' => 'string',
662+
'location' => 'uri',
663+
'minLength' => 1,
664+
'filters' => array(
665+
'Qcloud\\Cos\\Client::explodeKey'
666+
)
667+
),
668+
'TagSet' => array(
669+
'required' => true,
670+
'type' => 'array',
671+
'location' => 'xml',
672+
'items' => array(
673+
'name' => 'TagRule',
674+
'type' => 'object',
675+
'sentAs' => 'Tag',
676+
'properties' => array(
677+
'Key' => array(
678+
'required' => true,
679+
'type' => 'string',
680+
),
681+
'Value' => array(
682+
'required' => true,
683+
'type' => 'string',
684+
),
685+
),
686+
),
687+
),
688+
),
689+
),
690+
// 获取对象标签信息的方法
691+
'GetObjectTagging' => array(
692+
'httpMethod' => 'GET',
693+
'uri' => '/{Bucket}{/Key*}?tagging',
694+
'class' => 'Qcloud\\Cos\\Command',
695+
'responseClass' => 'GetObjectTaggingOutput',
696+
'responseType' => 'model',
697+
'parameters' => array(
698+
'Bucket' => array(
699+
'required' => true,
700+
'type' => 'string',
701+
'location' => 'uri',
702+
),
703+
'Key' => array(
704+
'required' => true,
705+
'type' => 'string',
706+
'location' => 'uri',
707+
'minLength' => 1,
708+
'filters' => array(
709+
'Qcloud\\Cos\\Client::explodeKey'
710+
)
711+
)
712+
),
713+
),
714+
// 删除对象标签的方法
715+
'DeleteObjectTagging' => array(
716+
'httpMethod' => 'DELETE',
717+
'uri' => '/{Bucket}{/Key*}?tagging',
718+
'class' => 'Qcloud\\Cos\\Command',
719+
'responseClass' => 'DeleteObjectTaggingOutput',
720+
'responseType' => 'model',
721+
'parameters' => array(
722+
'Bucket' => array(
723+
'required' => true,
724+
'type' => 'string',
725+
'location' => 'uri'
726+
),
727+
'Key' => array(
728+
'required' => true,
729+
'type' => 'string',
730+
'location' => 'uri',
731+
'minLength' => 1,
732+
'filters' => array(
733+
'Qcloud\\Cos\\Client::explodeKey'
734+
)
735+
)
736+
)
737+
),
640738
// 下载对象的方法.
641739
'GetObject' => array(
642740
'httpMethod' => 'GET',
@@ -1019,7 +1117,7 @@ public static function getService() {
10191117
),
10201118
'ContentMD5' => array(
10211119
'type' => array(
1022-
'string',
1120+
// 'string',
10231121
'boolean'
10241122
),
10251123
'location' => 'header',
@@ -1134,7 +1232,7 @@ public static function getService() {
11341232
),
11351233
'ContentMD5' => array(
11361234
'type' => array(
1137-
'string',
1235+
// 'string',
11381236
'boolean'
11391237
),
11401238
'location' => 'header',
@@ -3550,6 +3648,55 @@ public static function getService() {
35503648
),
35513649
),
35523650
),
3651+
//设置对象标签
3652+
'PutObjectTaggingOutput' => array(
3653+
'type' => 'object',
3654+
'additionalProperties' => true,
3655+
'properties' => array(
3656+
'RequestId' => array(
3657+
'location' => 'header',
3658+
'sentAs' => 'x-cos-request-id',
3659+
),
3660+
),
3661+
),
3662+
//查询对象标签
3663+
'GetObjectTaggingOutput' => array(
3664+
'type' => 'object',
3665+
'additionalProperties' => true,
3666+
'properties' => array(
3667+
'TagSet' => array(
3668+
'type' => 'array',
3669+
'location' => 'xml',
3670+
'items' => array(
3671+
'sentAs' => 'Tag',
3672+
'type' => 'object',
3673+
'properties' => array(
3674+
'Key' => array(
3675+
'type' => 'string',
3676+
),
3677+
'Value' => array(
3678+
'type' => 'string',
3679+
),
3680+
),
3681+
),
3682+
),
3683+
'RequestId' => array(
3684+
'location' => 'header',
3685+
'sentAs' => 'x-cos-request-id',
3686+
),
3687+
),
3688+
),
3689+
//删除对象标签
3690+
'DeleteObjectTaggingOutput' => array(
3691+
'type' => 'object',
3692+
'additionalProperties' => true,
3693+
'properties' => array(
3694+
'RequestId' => array(
3695+
'location' => 'header',
3696+
'sentAs' => 'x-cos-request-id'
3697+
)
3698+
)
3699+
),
35533700
'GetObjectOutput' => array(
35543701
'type' => 'object',
35553702
'additionalProperties' => true,

0 commit comments

Comments
 (0)