From b0b2bee3cac366ba329f0a545049aeb8fa02115d Mon Sep 17 00:00:00 2001 From: tuuna <550566181@qq.com> Date: Wed, 7 Jul 2021 21:22:15 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/deleteObjectTagging.php | 25 +++++++++++++++++++++++ src/Qcloud/Cos/Service.php | 34 ++++++++++++++++++++++++++++++++ src/Qcloud/Cos/Tests/COSTest.php | 21 ++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 sample/deleteObjectTagging.php diff --git a/sample/deleteObjectTagging.php b/sample/deleteObjectTagging.php new file mode 100644 index 00000000..df6a2292 --- /dev/null +++ b/sample/deleteObjectTagging.php @@ -0,0 +1,25 @@ + $region, + 'schema' => 'https', //协议头部,默认为http + 'credentials'=> array( + 'secretId' => $secretId , + 'secretKey' => $secretKey))); +try { + $result = $cosClient->deleteObjectTagging(array( + 'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID + 'Key' => 'exampleobject', + )); + // 请求成功 + print_r($result); +} catch (\Exception $e) { + // 请求失败 + echo($e); +} \ No newline at end of file diff --git a/src/Qcloud/Cos/Service.php b/src/Qcloud/Cos/Service.php index 3ea33dcd..22755c77 100644 --- a/src/Qcloud/Cos/Service.php +++ b/src/Qcloud/Cos/Service.php @@ -637,6 +637,30 @@ public static function getService() { ), ), ), + // 删除对象标签的方法 + 'DeleteObjectTagging' => array( + 'httpMethod' => 'DELETE', + 'uri' => '/{Bucket}{/Key*}?tagging', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'DeleteObjectTaggingOutput', + 'responseType' => 'model', + 'parameters' => array( + 'Bucket' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri' + ), + 'Key' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey' + ) + ) + ) + ), // 下载对象的方法. 'GetObject' => array( 'httpMethod' => 'GET', @@ -3550,6 +3574,16 @@ public static function getService() { ), ), ), + 'DeleteObjectTaggingOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'RequestId' => array( + 'location' => 'header', + 'sentAs' => 'x-cos-request-id' + ) + ) + ), 'GetObjectOutput' => array( 'type' => 'object', 'additionalProperties' => true, diff --git a/src/Qcloud/Cos/Tests/COSTest.php b/src/Qcloud/Cos/Tests/COSTest.php index 3d535c5d..74b46d5c 100644 --- a/src/Qcloud/Cos/Tests/COSTest.php +++ b/src/Qcloud/Cos/Tests/COSTest.php @@ -1797,4 +1797,25 @@ public function testSelectObjectContent() } } + /* + * 正常delete对象标签 + * 200 + */ + public function testDeleteObjectTagging() + { + $key = '你好.txt'; + try { + $result = $this->cosClient->deleteObjectTagging(array( + // Bucket is required + 'Bucket' => $this->bucket, + // Key(Object) is required + 'Key' => $key + )); + print_r($result); + $this->assertTrue(True); + } catch (ServiceResponseException $e) { + print $e; + $this->assertFalse(TRUE); + } + } } From c9c616dd9abed5397c239a87b95b3df804dd9b85 Mon Sep 17 00:00:00 2001 From: tuuna <550566181@qq.com> Date: Thu, 8 Jul 2021 12:22:16 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E8=AE=BE=E7=BD=AE=E6=9F=A5=E8=AF=A2=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/getObjectTagging.php | 25 +++++++ sample/putObjectTagging.php | 33 +++++++++ src/Qcloud/Cos/Service.php | 113 +++++++++++++++++++++++++++++++ src/Qcloud/Cos/Tests/COSTest.php | 59 ++++++++++++++++ 4 files changed, 230 insertions(+) create mode 100644 sample/getObjectTagging.php create mode 100644 sample/putObjectTagging.php diff --git a/sample/getObjectTagging.php b/sample/getObjectTagging.php new file mode 100644 index 00000000..ad8df15a --- /dev/null +++ b/sample/getObjectTagging.php @@ -0,0 +1,25 @@ + $region, + 'schema' => 'https', //协议头部,默认为http + 'credentials' => array( + 'secretId' => $secretId, + 'secretKey' => $secretKey))); +try { + $result = $cosClient->getObjectTagging(array( + 'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID + 'Key' => 'exampleobject' + )); + // 请求成功 + print_r($result); +} catch (\Exception $e) { + // 请求失败 + echo($e); +} + diff --git a/sample/putObjectTagging.php b/sample/putObjectTagging.php new file mode 100644 index 00000000..6112ca44 --- /dev/null +++ b/sample/putObjectTagging.php @@ -0,0 +1,33 @@ + $region, + 'schema' => 'https', //协议头部,默认为http + 'credentials'=> array( + 'secretId' => $secretId , + 'secretKey' => $secretKey))); +try { + $result = $cosClient->putObjectTagging(array( + 'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID + 'Key' => 'exampleobject', + 'TagSet' => array( + array('Key'=>'key1', + 'Value'=>'value1', + ), + array('Key'=>'key2', + 'Value'=>'value2', + ), + ), + )); + // 请求成功 + print_r($result); +} catch (\Exception $e) { + // 请求失败 + echo "$e\n"; +} \ No newline at end of file diff --git a/src/Qcloud/Cos/Service.php b/src/Qcloud/Cos/Service.php index 22755c77..8c9f0c08 100644 --- a/src/Qcloud/Cos/Service.php +++ b/src/Qcloud/Cos/Service.php @@ -637,6 +637,80 @@ public static function getService() { ), ), ), + // 配置对象标签的方法. + 'PutObjectTagging' => array( + 'httpMethod' => 'PUT', + 'uri' => '/{Bucket}{/Key*}?tagging', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'PutObjectTaggingOutput', + 'responseType' => 'model', + 'data' => array( + 'xmlRoot' => array( + 'name' => 'Tagging', + ), + 'contentMd5' => true, + ), + 'parameters' => array( + 'Bucket' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + ), + 'Key' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey' + ) + ), + 'TagSet' => array( + 'required' => true, + 'type' => 'array', + 'location' => 'xml', + 'items' => array( + 'name' => 'TagRule', + 'type' => 'object', + 'sentAs' => 'Tag', + 'properties' => array( + 'Key' => array( + 'required' => true, + 'type' => 'string', + ), + 'Value' => array( + 'required' => true, + 'type' => 'string', + ), + ), + ), + ), + ), + ), + // 获取对象标签信息的方法 + 'GetObjectTagging' => array( + 'httpMethod' => 'GET', + 'uri' => '/{Bucket}{/Key*}?tagging', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'GetObjectTaggingOutput', + 'responseType' => 'model', + 'parameters' => array( + 'Bucket' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + ), + 'Key' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey' + ) + ) + ), + ), // 删除对象标签的方法 'DeleteObjectTagging' => array( 'httpMethod' => 'DELETE', @@ -3574,6 +3648,45 @@ public static function getService() { ), ), ), + //设置对象标签 + 'PutObjectTaggingOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'RequestId' => array( + 'location' => 'header', + 'sentAs' => 'x-cos-request-id', + ), + ), + ), + //查询对象标签 + 'GetObjectTaggingOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'TagSet' => array( + 'type' => 'array', + 'location' => 'xml', + 'items' => array( + 'sentAs' => 'Tag', + 'type' => 'object', + 'properties' => array( + 'Key' => array( + 'type' => 'string', + ), + 'Value' => array( + 'type' => 'string', + ), + ), + ), + ), + 'RequestId' => array( + 'location' => 'header', + 'sentAs' => 'x-cos-request-id', + ), + ), + ), + //删除对象标签 'DeleteObjectTaggingOutput' => array( 'type' => 'object', 'additionalProperties' => true, diff --git a/src/Qcloud/Cos/Tests/COSTest.php b/src/Qcloud/Cos/Tests/COSTest.php index 74b46d5c..b42e3a45 100644 --- a/src/Qcloud/Cos/Tests/COSTest.php +++ b/src/Qcloud/Cos/Tests/COSTest.php @@ -1797,6 +1797,65 @@ public function testSelectObjectContent() } } + /* + * 正常put对象标签 + * 200 + */ + public function testPutObjectTagging() + { + $key = '你好.txt'; + $testTaggingKeys = array( + 'key1', 'key2' + ); + $testTaggingValues = array( + 'value1', 'value2' + ); + try { + $result = $this->cosClient->putObjectTagging(array( + // Bucket is required + 'Bucket' => $this->bucket, + // Key(Object) is required + 'Key' => $key, + // tagging(key-value) is required + 'TagSet' => array( + array('Key'=> $testTaggingKeys[0], + 'Value'=> $testTaggingValues[0], + ), + array('Key'=> $testTaggingKeys[1], + 'Value'=> $testTaggingValues[1], + ), + ) + )); + print_r($result); + $this->assertTrue(True); + } catch (ServiceResponseException $e) { + print $e; + $this->assertFalse(TRUE); + } + } + + /* + * 正常get对象标签 + * 200 + */ + public function testGetObjectTagging() + { + $key = '你好.txt'; + try { + $result = $this->cosClient->getObjectTagging(array( + // Bucket is required + 'Bucket' => $this->bucket, + // Key(Object) is required + 'Key' => $key + )); + print_r($result); + $this->assertTrue(True); + } catch (ServiceResponseException $e) { + print $e; + $this->assertFalse(TRUE); + } + } + /* * 正常delete对象标签 * 200 From cb4355455c908fb7acea6d84f8f2cbc5e5c6f485 Mon Sep 17 00:00:00 2001 From: tuuna <550566181@qq.com> Date: Tue, 13 Jul 2021 09:55:28 +0800 Subject: [PATCH 3/4] =?UTF-8?q?contentMd5=E4=BB=85=E6=94=AF=E6=8C=81boolea?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Qcloud/Cos/Service.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Qcloud/Cos/Service.php b/src/Qcloud/Cos/Service.php index 8c9f0c08..c1a6f210 100644 --- a/src/Qcloud/Cos/Service.php +++ b/src/Qcloud/Cos/Service.php @@ -1117,7 +1117,7 @@ public static function getService() { ), 'ContentMD5' => array( 'type' => array( - 'string', +// 'string', 'boolean' ), 'location' => 'header', @@ -1232,7 +1232,7 @@ public static function getService() { ), 'ContentMD5' => array( 'type' => array( - 'string', +// 'string', 'boolean' ), 'location' => 'header', From b910cab2c5b8c93996ae0827ea87cc710c0f0a17 Mon Sep 17 00:00:00 2001 From: tuuna <550566181@qq.com> Date: Wed, 14 Jul 2021 17:09:56 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0UT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Qcloud/Cos/Tests/COSTest.php | 104 ++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 21 deletions(-) diff --git a/src/Qcloud/Cos/Tests/COSTest.php b/src/Qcloud/Cos/Tests/COSTest.php index b42e3a45..1fb5ee16 100644 --- a/src/Qcloud/Cos/Tests/COSTest.php +++ b/src/Qcloud/Cos/Tests/COSTest.php @@ -10,11 +10,21 @@ class COSTest extends \PHPUnit\Framework\TestCase private $cosClient; private $bucket; private $region; + private $object2; + private $testTaggingKeys; + private $testTaggingValues; protected function setUp(): void { $this->bucket = getenv('COS_BUCKET'); $this->region = getenv('COS_REGION'); $this->bucket2 = "tmp".$this->bucket; + $this->object2 = "key"; + $this->testTaggingKeys = array( + 'key1', 'key2' + ); + $this->testTaggingValues = array( + 'value1', 'value2' + ); $this->cosClient = new Client(array('region' => $this->region, 'credentials' => array( 'secretId' => getenv('COS_KEY'), @@ -1804,29 +1814,30 @@ public function testSelectObjectContent() public function testPutObjectTagging() { $key = '你好.txt'; - $testTaggingKeys = array( - 'key1', 'key2' - ); - $testTaggingValues = array( - 'value1', 'value2' + $tagSet = array( + array('Key'=> $this->testTaggingKeys[0], + 'Value'=> $this->testTaggingValues[0], + ), + array('Key'=> $this->testTaggingKeys[1], + 'Value'=> $this->testTaggingValues[1], + ), ); try { - $result = $this->cosClient->putObjectTagging(array( + $this->cosClient->putObjectTagging(array( // Bucket is required 'Bucket' => $this->bucket, // Key(Object) is required 'Key' => $key, // tagging(key-value) is required - 'TagSet' => array( - array('Key'=> $testTaggingKeys[0], - 'Value'=> $testTaggingValues[0], - ), - array('Key'=> $testTaggingKeys[1], - 'Value'=> $testTaggingValues[1], - ), - ) + 'TagSet' => $tagSet )); - print_r($result); + $rt = $this->cosClient->getObjectTagging(array( + // Bucket is required + 'Bucket' => $this->bucket, + // Key(Object) is required + 'Key' => $key + )); + $this->assertEquals($rt['TagSet'], $tagSet); $this->assertTrue(True); } catch (ServiceResponseException $e) { print $e; @@ -1841,14 +1852,26 @@ public function testPutObjectTagging() public function testGetObjectTagging() { $key = '你好.txt'; + $tagSet = array( + array('Key'=> $this->testTaggingKeys[0], + 'Value'=> $this->testTaggingValues[0], + ), + array('Key'=> $this->testTaggingKeys[1], + 'Value'=> $this->testTaggingValues[1], + ), + ); try { - $result = $this->cosClient->getObjectTagging(array( + $this->cosClient->putObjectTagging(array( + 'Bucket' => $this->bucket, + 'Key' => $key, + 'TagSet' => $tagSet + )); + $this->cosClient->getObjectTagging(array( // Bucket is required 'Bucket' => $this->bucket, // Key(Object) is required 'Key' => $key )); - print_r($result); $this->assertTrue(True); } catch (ServiceResponseException $e) { print $e; @@ -1863,18 +1886,57 @@ public function testGetObjectTagging() public function testDeleteObjectTagging() { $key = '你好.txt'; + $tagSet = array( + array('Key'=> $this->testTaggingKeys[0], + 'Value'=> $this->testTaggingValues[0], + ), + array('Key'=> $this->testTaggingKeys[1], + 'Value'=> $this->testTaggingValues[1], + ), + ); try { - $result = $this->cosClient->deleteObjectTagging(array( - // Bucket is required + $this->cosClient->putObjectTagging(array( + 'Bucket' => $this->bucket, + 'Key' => $key, + 'TagSet' => $tagSet + )); + $this->cosClient->deleteObjectTagging(array( 'Bucket' => $this->bucket, - // Key(Object) is required 'Key' => $key )); - print_r($result); $this->assertTrue(True); } catch (ServiceResponseException $e) { print $e; $this->assertFalse(TRUE); } } + + /* + * get object tagging,object不存在 + * NoSuchKey + * 404 + */ + public function testPutObjectTaggingObjectNonExisted() + { + $tagSet = array( + array('Key'=> $this->testTaggingKeys[0], + 'Value'=> $this->testTaggingValues[0], + ), + array('Key'=> $this->testTaggingKeys[1], + 'Value'=> $this->testTaggingValues[1], + ), + ); + try { + $this->cosClient->putObjectTagging( + array( + 'Bucket' => $this->bucket, + 'Key' => $this->object2, + 'TagSet' => $tagSet + ) + ); + $this->assertTrue(false); + } catch (ServiceResponseException $e) { + $this->assertTrue($e->getExceptionCode() === 'NoSuchKey' && $e->getStatusCode() === 404); + } + } }