From b209c0ba238aa78809b397e2d5c00da1180adbae Mon Sep 17 00:00:00 2001 From: lewzylu <327874225@qq.com> Date: Tue, 26 Dec 2017 22:00:59 +0800 Subject: [PATCH 1/2] update v4 --- README.md | 354 +++++++++++--- sample.php | 110 ++++- src/Qcloud/Cos/BucketStyleListener.php | 2 +- src/Qcloud/Cos/Client.php | 53 ++- src/Qcloud/Cos/Service.php | 632 +++++++++++++++++++++---- 5 files changed, 975 insertions(+), 176 deletions(-) diff --git a/README.md b/README.md index 37a6503e..25b8747b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ -## 接口列表 +## 基本 API 描述 +> 关于文章中出现的 SecretId、SecretKey、Bucket 等名称的含义和获取方式请参考:[COS 术语信息](https://cloud.tencent.com/document/product/436/7751) -### 获取桶列表 listBuckets +### 获取Bucket列表 #### 方法原型 ```php public Guzzle\Service\Resource\Model listBucket(array $args = array()) @@ -13,7 +14,7 @@ public Guzzle\Service\Resource\Model listBucket(array $args = array()) $result = $cosClient->listBuckets(); ``` -### 创建桶 createBucket +### 创建Bucket #### 方法原型 @@ -35,10 +36,11 @@ $args是包含以下字段的关联数组: ```php //创建桶 -$result = $cosClient->createBucket(array('Bucket' => 'testbucket-1250000000')); +//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 +$result = $cosClient->createBucket(array('Bucket' => 'testbucket-125000000')); ``` -### 删除桶 deleteBucket +### 删除Bucket #### 方法原型 @@ -59,10 +61,11 @@ $args是包含以下字段的关联数组: ```php //删除桶 -$result = $cosClient->deleteBucket(array('Bucket' => 'testbucket-1250000000')); +//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 +$result = $cosClient->deleteBucket(array('Bucket' => 'testbucket-125000000')); ``` -### 简单文件上传 putobject +### 简单文件上传 #### 方法原型 @@ -74,33 +77,87 @@ public Guzzle\Service\Resource\Model putObject(array $args = array()) $args是包含以下字段的关联数组: -| 字段名 | 类型 | 默认值 | 是否必填字段 | 描述 | -| :------: | :------------: | :--: | :--------: | :----------------------------------: | -| Bucket | string | 无 | 是 | bucket名称 | -| Key | string | 无 | 是 | 对象名称 | -| Body | string\|resource | 无 | 是 | 对象的内容 | -| Acl | string | 无 | 否 | ACL权限控制 | -| Metadata | associative-array | 无 | 否 | 用户的自定义头(x-cos-meta-)和HTTP头(metadata) | - +| 参数名称 | 描述 |类型 | 是否必填字段 | +| -------------- | -------------- |---------- | ----------- | + | Bucket | Bucket 名称,由数字和小写字母以及中划线 "-" 构成 | string | 是 | + | Body | 上传文件的内容,可以为文件流或字节流 | file/string | 是 | + | Key | 上传文件的路径名,默认从 Bucket 开始 | string | 是 | + | ACL | 设置文件的 ACL,如 'private,public-read','public-read-write' | string | 否 | + | GrantFullControl |赋予指定账户对文件的读写权限 | string | 否 | + | GrantRead | 赋予指定账户对文件读权限 | string | 否 | + | GrantWrite | 赋予指定账户对文件的写权限 | string | 否 | + | StorageClass | 设置文件的存储类型,STANDARD,STANDARD_IA,NEARLINE,默认值:STANDARD | String | 否 | + | Expires | 设置 Content-Expires | string| 否 | + | CacheControl | 缓存策略,设置 Cache-Control | string | 否 | + | ContentType | 内容类型,设置 Content-Type |string | 否 | + | ContentDisposition | 文件名称,设置 Content-Disposition | string | 否 | + | ContentEncoding | 编码格式,设置 Content-Encoding | string | 否 | + | ContentLanguage | 语言类型,设置 Content-Language | string | 否 | + | ContentLength | 设置传输长度 | string | 否 | + | ContentMD5 | 设置上传文件的 MD5 值用于校验 | string | 否 | + | Metadata | 用户自定义的文件元信息 | array | 否 | #### 示例 ```php // 从内存中上传 -$cosClient->putObject(array( - 'Bucket' => 'testbucket-1250000000', - 'Key' => 'hello.txt', - 'Body' => 'Hello World!')); - +#putObject +try { + $result = $cosClient->putObject(array( + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' => 'testbucket-125000000', + 'Key' => 'string', + 'Body' => 'Hello World!', + 'CacheControl' => 'string', + 'ContentDisposition' => 'string', + 'ContentEncoding' => 'string', + 'ContentLanguage' => 'string', +// 'ContentLength' => integer, +// 'ContentType' => 'string', +// 'Expires' => 'mixed type: string (date format)|int (unix timestamp)|\DateTime', +// 'GrantFullControl' => 'string', +// 'GrantRead' => 'string', +// 'GrantWrite' => 'string', +// 'Metadata' => array( +// 'string' => 'string', +// ), +// 'StorageClass' => 'string', + )); + print_r($result); +} catch (\Exception $e) { + echo "$e\n"; +} // 上传本地文件 -$cosClient->putObject(array( - 'Bucket' => 'testbucket-1250000000', - 'Key' => 'hello.txt', - 'Body' => fopen('./hello.txt', 'rb'))); +#putObject +try { + $result = $cosClient->putObject(array( + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' => 'testbucket-125000000', + 'Key' => 'string', + 'Body' => fopen('./hello.txt', 'rb'), + 'CacheControl' => 'string', + 'ContentDisposition' => 'string', + 'ContentEncoding' => 'string', + 'ContentLanguage' => 'string', +// 'ContentLength' => integer, +// 'ContentType' => 'string', +// 'Expires' => 'mixed type: string (date format)|int (unix timestamp)|\DateTime', +// 'GrantFullControl' => 'string', +// 'GrantRead' => 'string', +// 'GrantWrite' => 'string', +// 'Metadata' => array( +// 'string' => 'string', +// ), +// 'StorageClass' => 'string', + )); + print_r($result); +} catch (\Exception $e) { + echo "$e\n"; +} ``` -### 分块文件上传 multiupload +### 分块文件上传 分块文件上传是通过将文件拆分成多个小块进行上传,多个小块可以并发上传, 最大支持40TB。 @@ -130,19 +187,28 @@ public Guzzle\Service\Resource\Model listParts(array $args = array()); // 终止分块上传 public Guzzle\Service\Resource\Model abortMultipartUpload(array $args = array()); ``` -### 上传文件 upload +### 上传文件 #### 示例 ```php //上传文件 -$result = $cosClient->upload( - $bucket = 'testbucket-1250000000', - $key = '111.txt', - $body = '131213'); +try { + $result = $cosClient->upload( + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + $bucket='testbucket-1252448703', + $key = '111.txt', + $body = fopen('./hello.txt', 'rb'), + $options = array( + "ACL"=>'private', + 'CacheControl' => 'private')); + print_r($result); +} catch (\Exception $e) { + echo "$e\n"; +} ``` 单文件小于5M时,使用单文件上传 反之使用分片上传 -### 下载文件 getobject +### 下载文件 将文件下载到本地或者下载到内存中. @@ -162,25 +228,29 @@ $args是包含以下字段的关联数组: | Bucket | string | 无 | 是 | bucket名称 | | Key | string | 无 | 是 | 对象名称 | | SaveAs | string | 无 | 否 | 保存到本地的本地文件路径 | +| VersionId | string | 无 | 否 | 对象版本号 | + #### 示例 ```php // 下载文件到内存 $result = $cosClient->getObject(array( - 'Bucket' => 'testbucket-1250000000', + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' => 'testbucket-125000000', 'Key' => 'hello.txt')); echo($result['Body']) // 下载文件到本地 $result = $cosClient->getObject(array( - 'Bucket' => 'testbucket-1250000000', + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' => 'testbucket-125000000', 'Key' => 'hello.txt', 'SaveAs' => './hello.txt')); ``` -### 删除文件 deleteobject +### 删除文件 删除COS上的对象. @@ -199,19 +269,21 @@ $args是包含以下字段的关联数组: | :------: | :------------: | :--: | :--------: | :----------------------------------: | | Bucket | string | 无 | 是 | bucket名称 | | Key | string | 无 | 是 | 对象名称 | +| VersionId | string | 无 | 否 | 对象版本号 | #### 示例 ```php // 删除COS对象 $result = $cosClient->deleteObject(array( - 'Bucket' => 'testbucket-1250000000', + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' => 'testbucket-125000000', 'Key' => 'hello.txt')); ``` -### 获取对象属性 headobject +### 获取对象属性 查询获取COS上的对象属性 @@ -230,17 +302,20 @@ $args是包含以下字段的关联数组: | :------: | :------------: | :--: | :--------: | :----------------------------------: | | Bucket | string | 无 | 是 | bucket名称 | | Key | string | 无 | 是 | 对象名称 | +| VersionId | string | 无 | 否 | 对象版本号 | + #### 示例 -```java +```php // 获取COS文件属性 -$result $cosClient->headObject(array('Bucket' => 'testbucket-1250000000', 'Key' => 'hello.txt')); + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 +$result $cosClient->headObject(array('Bucket' => 'testbucket-125000000', 'Key' => 'hello.txt')); ``` -### 获取文件列表 listbucket +### 获取文件列表 查询获取COS上的文件列表 @@ -267,7 +342,8 @@ $args是包含以下字段的关联数组: ```php // 获取bucket下成员 -$result = $cosClient->listObjects(array('Bucket' => 'testbucket-1250000000')); +//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 +$result = $cosClient->listObjects(array('Bucket' => 'testbucket-125000000')); ``` ### putBucketACL @@ -297,7 +373,8 @@ $args是包含以下字段的关联数组: #putBucketACL try { $result = $cosClient->PutBucketAcl(array( - 'Bucket' => 'testbucket-1250000000', + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' => 'testbucket-125000000', 'Grants' => array( array( 'Grantee' => array( @@ -339,7 +416,8 @@ public Guzzle\Service\Resource\Model getBucketACL(array $args = array()); #getBucketACL try { $result = $cosClient->GetBucketAcl(array( - 'Bucket' => 'testbucket-1250000000',)); + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' => 'testbucket-125000000',)); print_r($result); } catch (\Exception $e) { echo "$e\n"; @@ -368,7 +446,8 @@ public Guzzle\Service\Resource\Model putObjectACL(array $args = array()); #putObjectACL try { $result = $cosClient->PutBucketAcl(array( - 'Bucket' => 'testbucket-1250000000', + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' => 'testbucket-125000000', 'Grants' => array( array( 'Grantee' => array( @@ -409,7 +488,8 @@ public Guzzle\Service\Resource\Model getObjectACL(array $args = array()); #getObjectACL try { $result = $cosClient->getObjectAcl(array( - 'Bucket' => 'testbucket-1250000000', + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' => 'testbucket-125000000', 'Key' => '11')); print_r($result); } catch (\Exception $e) { @@ -442,8 +522,8 @@ public Guzzle\Service\Resource\Model putBucketCors(array $args = array()); ###putBucketCors try { $result = $cosClient->putBucketCors(array( - // Bucket is required - 'Bucket' => 'lewzylu02', + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' => 'testbucket-125000000', // CORSRules is required 'CORSRules' => array( array( @@ -482,8 +562,8 @@ public Guzzle\Service\Resource\Model getBucketCors(array $args = array()); #getBucketCors try { $result = $cosClient->getBucketCors(array( - // Bucket is required - 'Bucket' => 'lewzylu02', + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' => 'testbucket-125000000', )); print_r($result); } catch (\Exception $e) { @@ -507,8 +587,8 @@ public Guzzle\Service\Resource\Model deleteBucketCors(array $args = array()); #deleteBucketCors try { $result = $cosClient->deleteBucketCors(array( - // Bucket is required - 'Bucket' => 'lewzylu02', + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' => 'testbucket-125000000', )); print_r($result); } catch (\Exception $e) { @@ -516,7 +596,7 @@ try { } ``` -### 复制对象copyobject +### 复制对象 #### 方法原型 ```php @@ -540,8 +620,8 @@ $args是包含以下字段的关联数组: #copyobject try { $result = $cosClient->copyObject(array( - // Bucket is required - 'Bucket' => 'lewzylu02', + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' => 'testbucket-125000000', // CopySource is required 'CopySource' => 'lewzylu03-1252448703.cos.ap-guangzhou.myqcloud.com/tox.ini', // Key is required @@ -553,7 +633,16 @@ try { } ``` - +#Copy +try { + $result = $cosClient->Copy($bucket = 'lewzylu01-1252448703', + $key = 'string', + $copysource = 'lewzylu02-1252448703.cos.ap-guangzhou.myqcloud.com/test1G', + $options = array('VersionId'=>'MTg0NDY3NDI1NTk0MzUwNDQ1OTg')); + print_r($result); +} catch (\Exception $e) { + echo "$e\n"; +} ### putBucketLifecycle #### 方法原型 @@ -579,8 +668,8 @@ public Guzzle\Service\Resource\Model putBucketLifecycle(array $args = array()); #putBucketLifecycle try { $result = $cosClient->putBucketLifecycle(array( - // Bucket is required - 'Bucket' => 'lewzylu02', + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' => 'testbucket-125000000', // Rules is required 'Rules' => array( array( @@ -624,8 +713,8 @@ public Guzzle\Service\Resource\Model getBucketLifecycle(array $args = array()); #getBucketLifecycle try { $result = $cosClient->getBucketLifecycle(array( - // Bucket is required - 'Bucket' =>'lewzylu02', + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' =>'testbucket-125000000', )); print_r($result); } catch (\Exception $e) { @@ -649,8 +738,8 @@ public Guzzle\Service\Resource\Model deleteBucketLifecycle(array $args = array() #deleteBucketLifecycle try { $result = $cosClient->deleteBucketLifecycle(array( - // Bucket is required - 'Bucket' =>'lewzylu02', + //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 + 'Bucket' =>'testbucket-125000000', )); print_r($result); } catch (\Exception $e) { @@ -670,7 +759,8 @@ try { ```php //获得object的下载url -$bucket = 'testbucket-1250000000'; +//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 +$bucket = 'testbucket-125000000'; $key = 'hello.txt'; $region = 'cn-south'; $url = "/{$key}"; @@ -690,3 +780,145 @@ $cosClient = new Qcloud\Cos\Client( 'secretKey' => '', 'token' => ''))); ``` +### 恢复归档文件 + +#### 方法原型 + +```php +// 恢复归档文件 +public Guzzle\Service\Resource\Model deleteObject(array $args = array()); +``` + +#### 参数说明 + +$args是包含以下字段的关联数组: + +| 字段名 | 类型 | 默认值 | 是否必填字段 | 描述 | +| :------: | :------------: | :--: | :--------: | :----------------------------------: | +| Bucket | string | 无 | 是 | bucket名称 | +| Key | string | 无 | 是 | 对象名称 | +| Days | integer | 无 | 是 | 保存时间 | +| Tier | string | standard | 否 | 恢复类型 | + +#### 示例 + +```php + try { + $result = $cosClient->restoreObject(array( + // Bucket is required + 'Bucket' => 'lewzylu02', + // Objects is required + 'Key' => '11', + 'Days' => 7, + 'CASJobParameters' => array( + 'Tier' =>'Bulk' + ) + )); + print_r($result); +} catch (\Exception $e) { + echo "$e\n"; +}``` + +### 开启多版本 + +#### 方法原型 + +```php +// 开启多版本 +public Guzzle\Service\Resource\Model putBucketVersioning(array $args = array()); +``` + +#### 参数说明 + +$args是包含以下字段的关联数组: + +| 字段名 | 类型 | 默认值 | 是否必填字段 | 描述 | +| :------: | :------------: | :--: | :--------: | :----------------------------------: | +| Bucket | string | 无 | 是 | bucket名称 | +| Status | string | 无 | 是 | 多版本状态 | + +#### 示例 + +```php +#putBucketVersioning +try { + $result = $cosClient->putBucketVersioning( + array('Bucket' => 'lewzylu02', + 'Status' => 'Enabled') + ); + print_r($result); +} catch (\Exception $e) { + echo "$e\n"; +} + + +``` + +``` +### 获取bucket版本 + +#### 方法原型 + +```php +// 获取bucket版本 +public Guzzle\Service\Resource\Model getBucketVersioning(array $args = array()); +``` + +#### 参数说明 + +$args是包含以下字段的关联数组: + +| 字段名 | 类型 | 默认值 | 是否必填字段 | 描述 | +| :------: | :------------: | :--: | :--------: | :----------------------------------: | +| Bucket | string | 无 | 是 | bucket名称 | + +#### 示例 + +```php +try { + $result = $cosClient->getBucketVersioning( + array('Bucket' => 'lewzylu02',) + ); + print_r($result); +} catch (\Exception $e) { + echo "$e\n"; +} + +``` + +``` +### 打印各个版本的文件列表 + +#### 方法原型 + +```php +// 打印各个版本的文件列表 +public Guzzle\Service\Resource\Model listObjectVersions(array $args = array()); +``` + +#### 参数说明 + +$args是包含以下字段的关联数组: + +| 字段名 | 类型 | 默认值 | 是否必填字段 | 描述 | +| :------: | :------------: | :--: | :--------: | :----------------------------------: | +| Bucket | string | 无 | 是 | bucket名称 | +| Delimiter | string | 无 | 否 | 分隔符 | +| Marker | string | 无 | 否 | 标记 | +| MaxKeys | int | 无 | 否 | 最大对象个数 | +| Prefix | string | 无 | 否 | 前缀 | + +#### 示例 + +```php +try { + $result = $cosClient->listObjectVersions( + array('Bucket' => 'lewzylu02', + 'Prefix'=>'test1G') + ); + print_r($result); +} catch (\Exception $e) { + echo "$e\n"; +} + +``` diff --git a/sample.php b/sample.php index ff9a00dd..484fce4f 100644 --- a/sample.php +++ b/sample.php @@ -24,6 +24,7 @@ echo "$e\n"; } + #uploadbigfile try { $result = $cosClient->upload( @@ -38,6 +39,7 @@ echo "$e\n"; } + #putObject try { $result = $cosClient->putObject(array( @@ -49,15 +51,40 @@ echo "$e\n"; } + +#putBucketVersioning +try { + $result = $cosClient->putBucketVersioning( + array('Bucket' => 'lewzylu02', + 'Status' => 'Enabled') + ); + print_r($result); +} catch (\Exception $e) { + echo "$e\n"; +} + + #getObject try { $result = $cosClient->getObject(array( 'Bucket' => 'testbucket-1252448703', 'Key' => '11', + 'VersionId' =>'111' )); } catch (\Exception $e) { echo "$e\n"; } + +#getBucketLocation +try { + $result = $cosClient->getBucketLocation(array( + 'Bucket' => 'lewzylu02', + )); +} catch (\Exception $e) { + echo "$e\n"; +} +; + #deleteObject try { $result = $cosClient->deleteObject(array( @@ -67,6 +94,8 @@ } catch (\Exception $e) { echo "$e\n"; } + + #deleteObjects try { $result = $cosClient->deleteObjects(array( @@ -87,6 +116,7 @@ echo "$e\n"; } + #deleteBucket try { $result = $cosClient->deleteBucket(array( @@ -96,16 +126,19 @@ echo "$e\n"; } + #headObject try { $result = $cosClient->headObject(array( 'Bucket' => 'testbucket-1252448703', - 'Key' => '11')); + 'Key' => '11', + 'VersionId' =>'111')); print_r($result); } catch (\Exception $e) { echo "$e\n"; } + #listObjects try { $result = $cosClient->headObject(array( @@ -116,6 +149,18 @@ echo "$e\n"; } +#ListObjectVersions +try { + $result = $cosClient->ListObjectVersions( + array('Bucket' => 'lewzylu02', + 'Prefix'=>'test1G') + ); + print_r($result); +} catch (\Exception $e) { + echo "$e\n"; +} + + #listObjects try { $result = $cosClient->listObjects(array( @@ -124,7 +169,19 @@ } catch (\Exception $e) { echo "$e\n"; } -#putObjectUrl + +#getBucketVersioning +try { + $result = $cosClient->getBucketVersioning( + array('Bucket' => 'lewzylu02',) + ); + print_r($result); +} catch (\Exception $e) { + echo "$e\n"; +} + + +#getObjectUrl try { $bucket = 'testbucket-1252448703'; $key = 'hello.txt'; @@ -137,6 +194,8 @@ } catch (\Exception $e) { echo "$e\n"; } + + #putBucketACL try { $result = $cosClient->PutBucketAcl(array( @@ -160,6 +219,8 @@ } catch (\Exception $e) { echo "$e\n"; } + + #getBucketACL try { $result = $cosClient->GetBucketAcl(array( @@ -169,6 +230,7 @@ echo "$e\n"; } + #putObjectACL try { $result = $cosClient->PutBucketAcl(array( @@ -193,6 +255,7 @@ echo "$e\n"; } + #getObjectACL try { $result = $cosClient->getObjectAcl(array( @@ -202,6 +265,8 @@ } catch (\Exception $e) { echo "$e\n"; } + + #putBucketLifecycle try { $result = $cosClient->putBucketLifecycle(array( @@ -230,6 +295,8 @@ } catch (\Exception $e) { echo "$e\n"; } + + #getBucketLifecycle try { $result = $cosClient->getBucketLifecycle(array( @@ -241,6 +308,7 @@ echo "$e\n"; } + #deleteBucketLifecycle try { $result = $cosClient->deleteBucketLifecycle(array( @@ -251,6 +319,8 @@ } catch (\Exception $e) { echo "$e\n"; } + + #putBucketCors try { $result = $cosClient->putBucketCors(array( @@ -273,6 +343,8 @@ } catch (\Exception $e) { echo "$e\n"; } + + #getBucketCors try { $result = $cosClient->getBucketCors(array( @@ -283,6 +355,8 @@ } catch (\Exception $e) { echo "$e\n"; } + + #deleteBucketCors try { $result = $cosClient->deleteBucketCors(array( @@ -293,13 +367,15 @@ } catch (\Exception $e) { echo "$e\n"; } + + #copyobject try { $result = $cosClient->copyObject(array( // Bucket is required - 'Bucket' => 'testbucket-1252448703', + 'Bucket' => 'lewzylu01-1252448703', // CopySource is required - 'CopySource' => 'lewzylu03-1252448703.cos.ap-guangzhou.myqcloud.com/tox.ini', + 'CopySource' => 'lewzylu02-1252448703.cos.ap-guangzhou.myqcloud.com/test1G?versionId=MTg0NDY3NDI1NTk0MzUwNDQ1OTg', // Key is required 'Key' => 'string', )); @@ -307,12 +383,32 @@ } catch (\Exception $e) { echo "$e\n"; } + + #Copy try { - $result = $cosClient->Copy($bucket = 'testbucket-1252448703', - $key = 'cmake-3.8.2为.tar.gz', - $copysource = 'lewzylu-1252448703.cos.ap-guangzhou.myqcloud.com/cmake-3.8.2为.tar.gz'); + $result = $cosClient->Copy($bucket = 'lewzylu01-1252448703', + $key = 'string', + $copysource = 'lewzylu02-1252448703.cos.ap-guangzhou.myqcloud.com/test1G', + $options = array('VersionId'=>'MTg0NDY3NDI1NTk0MzUwNDQ1OTg')); print_r($result); } catch (\Exception $e) { echo "$e\n"; } +#restoreObject +try { + $result = $cosClient->restoreObject(array( + // Bucket is required + 'Bucket' => 'lewzylu02', + // Objects is required + 'Key' => '11', + 'Days' => 7, + 'CASJobParameters' => array( + 'Tier' =>'Bulk' + ) + )); + print_r($result); +} catch (\Exception $e) { + echo "$e\n"; +} + diff --git a/src/Qcloud/Cos/BucketStyleListener.php b/src/Qcloud/Cos/BucketStyleListener.php index 62fd5efc..a035d053 100644 --- a/src/Qcloud/Cos/BucketStyleListener.php +++ b/src/Qcloud/Cos/BucketStyleListener.php @@ -48,7 +48,7 @@ public function onCommandAfterPrepare(Event $event) { $command['Key'] = $key = implode('/', $key); } } - + $request->setHeader('Date', gmdate('D, d M Y H:i:s T')); $request->setPath(preg_replace("#^/{$bucket}#", '', $request->getPath())); if ($this->appId != null && endWith($bucket,'-'.$this->appId) == False) diff --git a/src/Qcloud/Cos/Client.php b/src/Qcloud/Cos/Client.php index 3d40b959..7ea3ce5c 100644 --- a/src/Qcloud/Cos/Client.php +++ b/src/Qcloud/Cos/Client.php @@ -100,7 +100,6 @@ public function upload($bucket, $key, $body, $options = array()) { $options = Collection::fromConfig(array_change_key_case($options), array( 'min_part_size' => MultipartUpload::MIN_PART_SIZE, 'params' => $options)); - print_r($options); if ($body->getSize() < $options['min_part_size']) { // Perform a simple PutObject operation return $this->putObject(array( @@ -132,28 +131,68 @@ public function copy($bucket, $key, $copysource, $options = array()) { 'appId' => $sourceappid, 'secretId' => $this->secretId, 'secretKey' => $this->secretKey))); - $rt = $cosClient->headObject(array('Bucket'=>$sourcebucket, - 'Key'=>$sourcekey)); + 'Key'=>$sourcekey, + 'VersionId'=>$options['params']['VersionId'])); $contentlength =$rt['ContentLength']; if ($contentlength < $options['min_part_size']) { return $this->copyObject(array( 'Bucket' => $bucket, 'Key' => $key, - 'CopySource' => $copysource, + 'CopySource' => $copysource."?versionId=".$options['params']['VersionId'], ) + $options['params']); } $copy = new Copy($this, $contentlength, $copysource, $options['min_part_size'], array( 'Bucket' => $bucket, 'Key' => $key, 'ContentLength' => $contentlength, - 'CopySource' => $copysource, + 'CopySource' => $copysource."?versionId=".$options['params']['VersionId'], ) + $options['params']); - return $copy->performUploading(); -} + return $copy->performUploading(); + } + /** + * Determines whether or not a bucket exists by name + * + * @param string $bucket The name of the bucket + * @param bool $accept403 Set to true if 403s are acceptable + * @param array $options Additional options to add to the executed command + * + * @return bool + */ + public function doesBucketExist($bucket, $accept403 = true, array $options = array()) + { + try { + $this->HeadBucket(array( + 'Bucket' => $bucket)); + return True; + }catch (\Exception $e){ + return False; + } + } + + /** + * Determines whether or not an object exists by name + * + * @param string $bucket The name of the bucket + * @param string $key The key of the object + * @param array $options Additional options to add to the executed command + * + * @return bool + */ + public function doesObjectExist($bucket, $key, array $options = array()) + { + try { + $this->HeadObject(array( + 'Bucket' => $bucket, + 'Key' => $key)); + return True; + }catch (\Exception $e){ + return False; + } + } public static function encodeKey($key) { return $key; return str_replace('%2F', '/', rawurlencode($key)); diff --git a/src/Qcloud/Cos/Service.php b/src/Qcloud/Cos/Service.php index 8f5aff5c..373ea48a 100644 --- a/src/Qcloud/Cos/Service.php +++ b/src/Qcloud/Cos/Service.php @@ -555,6 +555,11 @@ public static function getService() { 'format' => 'date-time-http', 'location' => 'query', 'sentAs' => 'response-expires'), + 'VersionId' => array( + 'type' => 'string', + 'location' => 'query', + 'sentAs' => 'versionId', + ), 'SaveAs' => array( 'location' => 'response_body')), 'errorResponses' => array( @@ -687,6 +692,20 @@ public static function getService() { ), ), ), + 'GetBucketLocation' => array( + 'httpMethod' => 'GET', + 'uri' => '/{Bucket}?location', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'GetBucketLocationOutput', + 'responseType' => 'model', + 'parameters' => array( + 'Bucket' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + ), + ), + ), 'UploadPart' => array( 'httpMethod' => 'PUT', 'uri' => '/{Bucket}{/Key*}', @@ -1305,15 +1324,15 @@ public static function getService() { ), ), ), - 'PutBucketVersioning' => array( - 'httpMethod' => 'PUT', - 'uri' => '/{Bucket}?versioning', + 'RestoreObject' => array( + 'httpMethod' => 'POST', + 'uri' => '/{Bucket}{/Key*}?restore', 'class' => 'Qcloud\\Cos\\Command', - 'responseClass' => 'PutBucketVersioningOutput', + 'responseClass' => 'RestoreObjectOutput', 'responseType' => 'model', 'data' => array( 'xmlRoot' => array( - 'name' => 'VersioningConfiguration', + 'name' => 'RestoreRequest', ), ), 'parameters' => array( @@ -1322,84 +1341,46 @@ public static function getService() { 'type' => 'string', 'location' => 'uri', ), - 'MFA' => array( - 'type' => 'string', - 'location' => 'header', - 'sentAs' => 'x-cos-mfa', - ), - 'MFADelete' => array( - 'type' => 'string', - 'location' => 'xml', - 'sentAs' => 'MfaDelete', - ), - 'Status' => array( - 'type' => 'string', - 'location' => 'xml', - ), - ), - ), - 'PutBucketReplication' => array( - 'httpMethod' => 'PUT', - 'uri' => '/{Bucket}?replication', - 'class' => 'Qcloud\\Cos\\Command', - 'responseClass' => 'PutBucketReplicationOutput', - 'responseType' => 'model', - 'data' => array( - 'xmlRoot' => array( - 'name' => 'ReplicationConfiguration', - ), - 'contentMd5' => true, - ), - 'parameters' => array( - 'Bucket' => array( + 'Key' => array( 'required' => true, 'type' => 'string', 'location' => 'uri', + 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey', + ), ), - 'Role' => array( - 'required' => true, + 'VersionId' => array( 'type' => 'string', - 'location' => 'xml', + 'location' => 'query', + 'sentAs' => 'versionId', ), - 'Rules' => array( + 'Days' => array( 'required' => true, - 'type' => 'array', + 'type' => 'numeric', 'location' => 'xml', - 'data' => array( - 'xmlFlattened' => true, - ), - 'items' => array( - 'name' => 'ReplicationRule', - 'type' => 'object', - 'sentAs' => 'Rule', - 'properties' => array( - 'ID' => array( - 'type' => 'string', - ), - 'Prefix' => array( - 'required' => true, - 'type' => 'string', - ), - 'Status' => array( - 'required' => true, - 'type' => 'string', - ), - 'Destination' => array( - 'required' => true, - 'type' => 'object', - 'properties' => array( - 'Bucket' => array( - 'required' => true, - 'type' => 'string', - ), - 'StorageClass' => array( - 'type' => 'string', - ), - ), - ), + ), + 'CASJobParameters' => array( + 'type' => 'object', + 'location' => 'xml', + 'properties' => array( + 'Tier' => array( + 'type' => 'string', + 'required' => true, ), ), ), + 'RequestPayer' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-request-payer', + ), + ), + 'errorResponses' => array( + array( + 'reason' => 'This operation is not allowed against this storage tier', + 'class' => 'ObjectAlreadyInActiveTierErrorException', + ), ), ), 'ListParts' => array( @@ -1487,28 +1468,162 @@ public static function getService() { ), ), ), + 'ListObjectVersions' => array( + 'httpMethod' => 'GET', + 'uri' => '/{Bucket}?versions', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'ListObjectVersionsOutput', + 'responseType' => 'model', + 'parameters' => array( + 'Bucket' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + ), + 'Delimiter' => array( + 'type' => 'string', + 'location' => 'query', + 'sentAs' => 'delimiter', + ), + 'EncodingType' => array( + 'type' => 'string', + 'location' => 'query', + 'sentAs' => 'encoding-type', + ), + 'KeyMarker' => array( + 'type' => 'string', + 'location' => 'query', + 'sentAs' => 'key-marker', + ), + 'MaxKeys' => array( + 'type' => 'numeric', + 'location' => 'query', + 'sentAs' => 'max-keys', + ), + 'Prefix' => array( + 'type' => 'string', + 'location' => 'query', + 'sentAs' => 'prefix', + ), + 'VersionIdMarker' => array( + 'type' => 'string', + 'location' => 'query', + 'sentAs' => 'version-id-marker', + ), + 'command.expects' => array( + 'static' => true, + 'default' => 'application/xml', + ), + ), + ), 'HeadObject' => array( 'httpMethod' => 'HEAD', 'uri' => '/{Bucket}{/Key*}', 'class' => 'Qcloud\\Cos\\Command', - 'responseType' => 'model', 'responseClass' => 'HeadObjectOutput', + 'responseType' => 'model', 'parameters' => array( 'Bucket' => array( 'required' => true, 'type' => 'string', - 'location' => 'uri'), + 'location' => 'uri', + ), + 'IfMatch' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'If-Match', + ), + 'IfModifiedSince' => array( + 'type' => array( + 'object', + 'string', + 'integer', + ), + 'format' => 'date-time-http', + 'location' => 'header', + 'sentAs' => 'If-Modified-Since', + ), + 'IfNoneMatch' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'If-None-Match', + ), + 'IfUnmodifiedSince' => array( + 'type' => array( + 'object', + 'string', + 'integer', + ), + 'format' => 'date-time-http', + 'location' => 'header', + 'sentAs' => 'If-Unmodified-Since', + ), 'Key' => array( 'required' => true, 'type' => 'string', 'location' => 'uri', 'minLength' => 1, 'filters' => array( - 'Qcloud\\Cos\\Client::explodeKey'))), + 'Qcloud\\Cos\\Client::explodeKey', + ), + ), + 'Range' => array( + 'type' => 'string', + 'location' => 'header', + ), + 'VersionId' => array( + 'type' => 'string', + 'location' => 'query', + 'sentAs' => 'versionId', + ), + 'SSECustomerAlgorithm' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-amz-server-side-encryption-customer-algorithm', + ), + 'SSECustomerKey' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-amz-server-side-encryption-customer-key', + ), + 'SSECustomerKeyMD5' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-amz-server-side-encryption-customer-key-MD5', + ), + 'RequestPayer' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-amz-request-payer', + ), + ), 'errorResponses' => array( array( 'reason' => 'The specified key does not exist.', - 'class' => 'NoSuchKeyException'))), + 'class' => 'NoSuchKeyException', + ), + ), + ), + 'HeadBucket' => array( + 'httpMethod' => 'HEAD', + 'uri' => '/{Bucket}', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'HeadBucketOutput', + 'responseType' => 'model', + 'parameters' => array( + 'Bucket' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + ), + ), + 'errorResponses' => array( + array( + 'reason' => 'The specified bucket does not exist.', + 'class' => 'NoSuchBucketException', + ), + ), + ), 'UploadPartCopy' => array( 'httpMethod' => 'PUT', 'uri' => '/{Bucket}{/Key*}', @@ -1663,6 +1778,11 @@ public static function getService() { 'ETag' => array( 'type' => 'string', 'location' => 'xml'), + 'VersionId' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-version-id', + ), 'RequestId' => array( 'location' => 'header', 'sentAs' => 'x-cos-request-id'))), @@ -1849,62 +1969,140 @@ public static function getService() { 'Body' => array( 'type' => 'string', 'instanceOf' => 'Guzzle\\Http\\EntityBody', - 'location' => 'body'), + 'location' => 'body', + ), + 'DeleteMarker' => array( + 'type' => 'boolean', + 'location' => 'header', + 'sentAs' => 'x-cos-delete-marker', + ), 'AcceptRanges' => array( 'type' => 'string', 'location' => 'header', - 'sentAs' => 'accept-ranges'), + 'sentAs' => 'accept-ranges', + ), + 'Expiration' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-expiration', + ), + 'Restore' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-restore', + ), 'LastModified' => array( 'type' => 'string', 'location' => 'header', - 'sentAs' => 'Last-Modified'), + 'sentAs' => 'Last-Modified', + ), 'ContentLength' => array( 'type' => 'numeric', 'location' => 'header', - 'sentAs' => 'Content-Length'), + 'sentAs' => 'Content-Length', + ), 'ETag' => array( - 'type' => 'string', - 'location' => 'header'), - 'CacheControl' => array( 'type' => 'string', 'location' => 'header', - 'sentAs' => 'Cache-Control'), + ), + 'MissingMeta' => array( + 'type' => 'numeric', + 'location' => 'header', + 'sentAs' => 'x-cos-missing-meta', + ), + 'VersionId' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-version-id', + ), + 'CacheControl' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'Cache-Control', + ), 'ContentDisposition' => array( 'type' => 'string', 'location' => 'header', - 'sentAs' => 'Content-Disposition'), + 'sentAs' => 'Content-Disposition', + ), 'ContentEncoding' => array( 'type' => 'string', 'location' => 'header', - 'sentAs' => 'Content-Encoding'), + 'sentAs' => 'Content-Encoding', + ), 'ContentLanguage' => array( 'type' => 'string', 'location' => 'header', - 'sentAs' => 'Content-Language'), + 'sentAs' => 'Content-Language', + ), 'ContentRange' => array( 'type' => 'string', 'location' => 'header', - 'sentAs' => 'Content-Range'), + 'sentAs' => 'Content-Range', + ), 'ContentType' => array( 'type' => 'string', 'location' => 'header', - 'sentAs' => 'Content-Type'), + 'sentAs' => 'Content-Type', + ), 'Expires' => array( 'type' => 'string', - 'location' => 'header'), + 'location' => 'header', + ), + 'WebsiteRedirectLocation' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-website-redirect-location', + ), + 'ServerSideEncryption' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-server-side-encryption', + ), 'Metadata' => array( 'type' => 'object', 'location' => 'header', 'sentAs' => 'x-cos-meta-', 'additionalProperties' => array( - 'type' => 'string')), - 'StorageClass' => array( 'type' => 'string', - 'location' => 'header', - 'sentAs' => 'x-cos-storage-class'), + ), + ), + 'SSECustomerAlgorithm' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-server-side-encryption-customer-algorithm', + ), + 'SSECustomerKeyMD5' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-server-side-encryption-customer-key-MD5', + ), + 'SSEKMSKeyId' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-server-side-encryption-aws-kms-key-id', + ), + 'StorageClass' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-storage-class', + ), + 'RequestCharged' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-request-charged', + ), + 'ReplicationStatus' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-replication-status', + ), 'RequestId' => array( - 'location' => 'header', - 'sentAs' => 'x-cos-request-id'))), + 'location' => 'header', + 'sentAs' => 'x-cos-request-id', + ), + ), + ), 'GetObjectAclOutput' => array( 'type' => 'object', 'additionalProperties' => true, @@ -2239,6 +2437,21 @@ public static function getService() { ), ), ), + 'GetBucketLocationOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'Location' => array( + 'type' => 'string', + 'location' => 'body', + 'filters' => array( + 'strval', + 'strip_tags', + 'trim', + ), + ), + ), + ), 'UploadPartOutput' => array( 'type' => 'object', 'additionalProperties' => true, @@ -2260,14 +2473,53 @@ public static function getService() { 'type' => 'object', 'additionalProperties' => true, 'properties' => array( + 'Expiration' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-expiration', + ), 'ETag' => array( 'type' => 'string', - 'location' => 'header'), + 'location' => 'header', + ), + 'ServerSideEncryption' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-server-side-encryption', + ), + 'VersionId' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-version-id', + ), + 'SSECustomerAlgorithm' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-server-side-encryption-customer-algorithm', + ), + 'SSECustomerKeyMD5' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-server-side-encryption-customer-key-MD5', + ), + 'SSEKMSKeyId' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-server-side-encryption-aws-kms-key-id', + ), + 'RequestCharged' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-request-charged', + ), 'RequestId' => array( - 'location' => 'header', - 'sentAs' => 'x-cos-request-id'), + 'location' => 'header', + 'sentAs' => 'x-cos-request-id', + ), 'ObjectURL' => array( - ))), + ), + ), + ), 'PutObjectAclOutput' => array( 'type' => 'object', 'additionalProperties' => true, @@ -2323,6 +2575,21 @@ public static function getService() { ), ), ), + 'RestoreObjectOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'RequestCharged' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-request-charged', + ), + 'RequestId' => array( + 'location' => 'header', + 'sentAs' => 'x-cos-request-id', + ), + ), + ), 'ListPartsOutput' => array( 'type' => 'object', 'additionalProperties' => true, @@ -2496,6 +2763,157 @@ public static function getService() { ), ), ), + 'ListObjectVersionsOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'IsTruncated' => array( + 'type' => 'boolean', + 'location' => 'xml', + ), + 'KeyMarker' => array( + 'type' => 'string', + 'location' => 'xml', + ), + 'VersionIdMarker' => array( + 'type' => 'string', + 'location' => 'xml', + ), + 'NextKeyMarker' => array( + 'type' => 'string', + 'location' => 'xml', + ), + 'NextVersionIdMarker' => array( + 'type' => 'string', + 'location' => 'xml', + ), + 'Versions' => array( + 'type' => 'array', + 'location' => 'xml', + 'sentAs' => 'Version', + 'data' => array( + 'xmlFlattened' => true, + ), + 'items' => array( + 'name' => 'ObjectVersion', + 'type' => 'object', + 'sentAs' => 'Version', + 'properties' => array( + 'ETag' => array( + 'type' => 'string', + ), + 'Size' => array( + 'type' => 'numeric', + ), + 'StorageClass' => array( + 'type' => 'string', + ), + 'Key' => array( + 'type' => 'string', + ), + 'VersionId' => array( + 'type' => 'string', + ), + 'IsLatest' => array( + 'type' => 'boolean', + ), + 'LastModified' => array( + 'type' => 'string', + ), + 'Owner' => array( + 'type' => 'object', + 'properties' => array( + 'DisplayName' => array( + 'type' => 'string', + ), + 'ID' => array( + 'type' => 'string', + ), + ), + ), + ), + ), + ), + 'DeleteMarkers' => array( + 'type' => 'array', + 'location' => 'xml', + 'sentAs' => 'DeleteMarker', + 'data' => array( + 'xmlFlattened' => true, + ), + 'items' => array( + 'name' => 'DeleteMarkerEntry', + 'type' => 'object', + 'sentAs' => 'DeleteMarker', + 'properties' => array( + 'Owner' => array( + 'type' => 'object', + 'properties' => array( + 'DisplayName' => array( + 'type' => 'string', + ), + 'ID' => array( + 'type' => 'string', + ), + ), + ), + 'Key' => array( + 'type' => 'string', + ), + 'VersionId' => array( + 'type' => 'string', + ), + 'IsLatest' => array( + 'type' => 'boolean', + ), + 'LastModified' => array( + 'type' => 'string', + ), + ), + ), + ), + 'Name' => array( + 'type' => 'string', + 'location' => 'xml', + ), + 'Prefix' => array( + 'type' => 'string', + 'location' => 'xml', + ), + 'Delimiter' => array( + 'type' => 'string', + 'location' => 'xml', + ), + 'MaxKeys' => array( + 'type' => 'numeric', + 'location' => 'xml', + ), + 'CommonPrefixes' => array( + 'type' => 'array', + 'location' => 'xml', + 'data' => array( + 'xmlFlattened' => true, + ), + 'items' => array( + 'name' => 'CommonPrefix', + 'type' => 'object', + 'properties' => array( + 'Prefix' => array( + 'type' => 'string', + ), + ), + ), + ), + 'EncodingType' => array( + 'type' => 'string', + 'location' => 'xml', + ), + 'RequestId' => array( + 'location' => 'header', + 'sentAs' => 'x-cos-request-id', + ), + ), + ), 'HeadObjectOutput' => array( 'type' => 'object', 'additionalProperties' => true, @@ -2537,9 +2955,23 @@ public static function getService() { 'type' => 'string', 'location' => 'header', 'sentAs' => 'x-cos-storage-class'), + 'VersionId' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-version-id'), 'RequestId' => array( 'location' => 'header', 'sentAs' => 'x-cos-request-id'))), + 'HeadBucketOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'RequestId' => array( + 'location' => 'header', + 'sentAs' => 'x-cos-request-id', + ), + ), + ), 'UploadPartCopyOutput' => array( 'type' => 'object', 'additionalProperties' => true, From b7939b15853cce09416d042a47d68d591bba4c2f Mon Sep 17 00:00:00 2001 From: lewzylu <327874225@qq.com> Date: Thu, 28 Dec 2017 15:46:21 +0800 Subject: [PATCH 2/2] md5 check --- src/Qcloud/Cos/MultipartUpload.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Qcloud/Cos/MultipartUpload.php b/src/Qcloud/Cos/MultipartUpload.php index ac3c13a0..1ae67fee 100644 --- a/src/Qcloud/Cos/MultipartUpload.php +++ b/src/Qcloud/Cos/MultipartUpload.php @@ -3,7 +3,7 @@ namespace Qcloud\Cos; use Guzzle\Http\ReadLimitEntityBody; - +use Qcloud\Cos\Exception\CosException; class MultipartUpload { /** * const var: part size from 5MB to 5GB, and max parts of 10000 are allowed for each upload. @@ -44,6 +44,11 @@ public function performUploading() { 'Body' => $body, 'UploadId' => $uploadId, 'PartNumber' => $partNumber)); +// echo(md5($body)); +// echo(substr($result['ETag'], 1, -1)); + if (md5($body) != substr($result['ETag'], 1, -1)){ + throw new CosException("ETag check inconsistency"); + } $part = array('PartNumber' => $partNumber, 'ETag' => $result['ETag']); array_push($parts, $part); ++$partNumber;