基本 API 描述

关于文章中出现的 SecretId、SecretKey、Bucket 等名称的含义和获取方式请参考:COS 术语信息

获取Bucket列表

方法原型

public Guzzle\Service\Resource\Model listBucket(array $args = array())

请求示例

//获取bucket列表

$result = $cosClient->listBuckets();

返回结果示例

Array

(

[data:protected] => Array

(

[Owner] => Array

(

[ID] => qcs::cam::uin/3210232098:uin/3210232098

[DisplayName] => 3210232098

)

[Buckets] => Array

(

[0] => Array

(

[Name] => accesslog-10055004

[Location] => ap-shanghai

[CreationDate] => 2016-07-29T03:09:54Z

)

[1] => Array

(

[Name] => accesslogbj-10055004

[Location] => ap-beijing

[CreationDate] => 2017-08-02T04:00:24Z

)

)

[RequestId] => NWE3YzgxZmFfYWZhYzM1MGFfMzc3MF9iOGY5OQ==

)

)

创建Bucket

方法原型

// 创建桶

public Guzzle\Service\Resource\Model createBucket(array $args = array());

请求参数

$args是包含以下字段的关联数组:

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

Acl

ACL权限控制

string

请求示例

//创建桶

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

$result = $cosClient->createBucket(array('Bucket' => 'testbucket-125000000'));

返回结果示例

Array

(

[data:protected] => Array

(

[Location] =>

[RequestId] => NWE3YzgzMTZfMTdiMjk0MGFfNTQ1OF8xNjEyYmE=

)

)

删除Bucket

方法原型

// 删除桶

public Guzzle\Service\Resource\Model deleteBucket(array $args = array());

请求参数

$args是包含以下字段的关联数组:

参数名称

描述

类型

是否必填字段

Bucket

string

bucket名称

请求示例

//删除桶

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

$result = $cosClient->deleteBucket(array('Bucket' => 'testbucket-125000000'));

返回结果示例

Array

(

[data:protected] => Array

(

[RequestId] => NWE3YzgzMTZfMTdiMjk0MGFfNTQ2MF8xNjBjZTI=

)

)

简单文件上传

方法原型

public Guzzle\Service\Resource\Model putObject(array $args = array())

请求参数

$args是包含以下字段的关联数组:

参数名称

描述

类型

是否必填字段

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

ServerSideEncryption

服务端加密方法

string

请求示例

// 从内存中上传

#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";

}

上传本地文件

#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";

}

返回结果示例

Array

(

[data:protected] => Array

(

[Expiration] =>

[ETag] => "ed076287532e86365e841e92bfc50d8c"

[ServerSideEncryption] => AES256

[VersionId] =>

[SSECustomerAlgorithm] =>

[SSECustomerKeyMD5] =>

[SSEKMSKeyId] =>

[RequestCharged] =>

[RequestId] => NWE3Yzg0M2NfOTcyMjViNjRfYTE1YV8xNTQzYTY=

[ObjectURL] => http://testbucket-1252448703.cos.cn-south.myqcloud.com/11%2F%2F32%2F%2F43

)

)

分块文件上传

分块文件上传是通过将文件拆分成多个小块进行上传,多个小块可以并发上传, 最大支持40TB。

分块文件上传的步骤为:

初始化分块上传,获取uploadid。(createMultipartUpload)

分块数据上传(可并发). (uploadPart)

完成分块上传。 (completeMultipartUpload)

另外还包含获取已上传分块(listParts), 终止分块上传(abortMultipartUpload)。

方法原型

// 初始化分块上传

public Guzzle\Service\Resource\Model createMultipartUpload(array $args = array());

// 上传数据分块

public Guzzle\Service\Resource\Model uploadPart(array $args = array());

// 完成分块上传

public Guzzle\Service\Resource\Model completeMultipartUpload(array $args = array());

// 罗列已上传分块

public Guzzle\Service\Resource\Model listParts(array $args = array());

// 终止分块上传

public Guzzle\Service\Resource\Model abortMultipartUpload(array $args = array());

上传文件

请求示例

//上传文件

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时,使用单文件上传

反之使用分片上传

返回结果示例

Array

(

[data:protected] => Array

(

[Location] => testbucket-1252448703.cos.cn-south.myqcloud.com/111.txt

[Bucket] => testbucket

[Key] => 111.txt

[ETag] => "715691804ee474f2eb94adb2c5c01155-1"

[Expiration] =>

[ServerSideEncryption] => AES256

[VersionId] =>

[SSEKMSKeyId] =>

[RequestCharged] =>

[RequestId] => NWE3Yzg0YTRfOTUyMjViNjRfNWYyZF8xNTI5ZDQ=

)

)

下载文件

将文件下载到本地或者下载到内存中.

方法原型

// 下载文件

public Guzzle\Service\Resource\Model getObject(array $args = array());

请求参数

$args是包含以下字段的关联数组:

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

Key

对象名称

string

SaveAs

保存到本地的本地文件路径

string

VersionId

对象版本号

string

请求示例

// 下载文件到内存

$result = $cosClient->getObject(array(

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

'Bucket' => 'testbucket-125000000',

'Key' => 'hello.txt'));

echo($result['Body'])

// 下载文件到本地

$result = $cosClient->getObject(array(

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

'Bucket' => 'testbucket-125000000',

'Key' => 'hello.txt',

'SaveAs' => './hello.txt'));

返回结果示例

Array

(

[data:protected] => Array

(

[Body] =>

[DeleteMarker] =>

[AcceptRanges] => bytes

[Expiration] =>

[Restore] =>

[LastModified] => Fri, 09 Feb 2018 01:10:56 GMT

[ContentLength] => 5242880

[ETag] => "715691804ee474f2eb94adb2c5c01155-1"

[MissingMeta] =>

[VersionId] =>

[CacheControl] => private

[ContentDisposition] => attachment; filename*="UTF-8''111.txt"

[ContentEncoding] =>

[ContentLanguage] =>

[ContentRange] =>

[ContentType] => text/plain; charset=utf-8

[Expires] =>

[WebsiteRedirectLocation] =>

[ServerSideEncryption] => AES256

[SSECustomerAlgorithm] =>

[SSECustomerKeyMD5] =>

[SSEKMSKeyId] =>

[StorageClass] =>

[RequestCharged] =>

[ReplicationStatus] =>

[RequestId] => NWE3Yzg4ODlfMThiMjk0MGFfMmI3OV8xNWQxNDg=

)

)

删除文件

删除COS上的对象.

方法原型

// 删除文件

public Guzzle\Service\Resource\Model deleteObject(array $args = array());

请求参数

$args是包含以下字段的关联数组:

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

Key

对象名称

string

VersionId

对象版本号

string

请求示例

// 删除COS对象

$result = $cosClient->deleteObject(array(

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

'Bucket' => 'testbucket-125000000',

'Key' => 'hello.txt'));

返回结果示例

Array

(

[data:protected] => Array

(

[DeleteMarker] =>

[VersionId] =>

[RequestCharged] =>

[RequestId] => NWE3Yzg5MzJfY2FhMzNiMGFfNDVjOV8yY2QyMzg=

)

)

获取对象属性

查询获取COS上的对象属性

方法原型

// 获取文件属性

public Guzzle\Service\Resource\Model headObject(array $args = array());

请求参数

$args是包含以下字段的关联数组:

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

Key

对象名称

string

VersionId

对象版本号

string

返回结果示例

Array

(

[data:protected] => Array

(

[DeleteMarker] =>

[AcceptRanges] =>

[Expiration] =>

[Restore] =>

[LastModified] => Thu, 08 Feb 2018 17:34:53 GMT

[ContentLength] => 12

[ETag] => "ed076287532e86365e841e92bfc50d8c"

[MissingMeta] =>

[VersionId] =>

[CacheControl] =>

[ContentDisposition] =>

[ContentEncoding] =>

[ContentLanguage] =>

[ContentType] => application/octet-stream

[Expires] =>

[WebsiteRedirectLocation] =>

[ServerSideEncryption] => AES256

[SSECustomerAlgorithm] =>

[SSECustomerKeyMD5] =>

[SSEKMSKeyId] =>

[StorageClass] =>

[RequestCharged] =>

[ReplicationStatus] =>

[RequestId] => NWE3YzhhM2RfMWViZTk0MGFfNWMzMF8xNTFiZDg=

)

)

请求示例

// 获取COS文件属性

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

$result $cosClient->headObject(array('Bucket' => 'testbucket-125000000', 'Key' => 'hello.txt'));

查询Bucket是否存在

查询获取COS上的Bucket是否存在

方法原型

// 获取文件属性

public Guzzle\Service\Resource\Model headBucket(array $args = array());

请求参数

$args是包含以下字段的关联数组:

参数名称

描述

类型

是否必填字段

Bucket

对象版本号

string

请求示例

// 获取COS文件属性

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

$result $cosClient->headBucket(array('Bucket' => 'testbucket-125000000'));

返回结果示例

Array

(

[data:protected] => Array

(

[RequestId] => NWE3YzhhN2VfY2VhMzNiMGFfMmNmXzJjNzc3Zg==

)

)

获取文件列表

查询获取COS上的文件列表

方法原型

// 获取文件列表

public Guzzle\Service\Resource\Model listObjects(array $args = array());

请求参数

$args是包含以下字段的关联数组:

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

Delimiter

分隔符

string

Marker

标记

string

MaxKeys

最大对象个数

int

Prefix

前缀

string

请求示例

// 获取bucket下成员

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

$result = $cosClient->listObjects(array('Bucket' => 'testbucket-125000000'));

返回结果示例

Array

(

[data:protected] => Array

(

[Name] => testbucket-1252448703

[Prefix] =>

[Marker] =>

[MaxKeys] => 1000

[IsTruncated] =>

[Contents] => Array

(

[0] => Array

(

[Key] => 11/32/43

[LastModified] => 2018-02-08T17:09:16.000Z

[ETag] => "ed076287532e86365e841e92bfc50d8c"

[Size] => 12

[Owner] => Array

(

[ID] => 1252448703

[DisplayName] => 1252448703

)

[StorageClass] => STANDARD

)

[1] => Array

(

[Key] => 111

[LastModified] => 2018-02-08T17:41:11.000Z

[ETag] => "ed076287532e86365e841e92bfc50d8c"

[Size] => 12

[Owner] => Array

(

[ID] => 1252448703

[DisplayName] => 1252448703

)

[StorageClass] => STANDARD

)

[2] => Array

(

[Key] => 111.txt

[LastModified] => 2018-02-08T17:11:00.000Z

[ETag] => "715691804ee474f2eb94adb2c5c01155-1"

[Size] => 5242880

[Owner] => Array

(

[ID] => 1252448703

[DisplayName] => 1252448703

)

[StorageClass] => STANDARD

)

)

[RequestId] => NWE3YzhiYjdfMWJiMjk0MGFfMzA4M18xNjdiNDM=

)

)

putBucketACL

方法原型

// 获取文件列表

public Guzzle\Service\Resource\Model putBucketACL(array $args = array());

请求参数

$args是包含以下字段的关联数组:

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

ACL

ACL权限控制

string

GrantRead

赋予被授权者读的权限。格式:id=" ",id=" ";当需要给子账户授权时,id="qcs::cam::uin/:uin/",当需要给根账户授权时,id="qcs::cam::uin/:uin/",例如:'id="qcs::cam::uin/123:uin/123", id="qcs::cam::uin/123:uin/456"'

string

GrantWrite

赋予被授权者写的权限。格式:id=" ",id=" ";当需要给子账户授权时,id="qcs::cam::uin/:uin/",当需要给根账户授权时,id="qcs::cam::uin/:uin/",例如:'id="qcs::cam::uin/123:uin/123", id="qcs::cam::uin/123:uin/456"'

string

GrantFullControl

赋予被授权者读写权限。格式:id=" ",id=" ";当需要给子账户授权时,id="qcs::cam::uin/:uin/",当需要给根账户授权时,id="qcs::cam::uin/:uin/",例如:'id="qcs::cam::uin/123:uin/123", id="qcs::cam::uin/123:uin/456"'

string

请求示例

#putBucketACL

try {

$result = $cosClient->PutBucketAcl(array(

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

'Bucket' => 'testbucket-125000000',

'Grants' => array(

array(

'Grantee' => array(

'DisplayName' => 'qcs::cam::uin/327874225:uin/327874225',

'ID' => 'qcs::cam::uin/327874225:uin/327874225',

'Type' => 'CanonicalUser',

),

'Permission' => 'FULL_CONTROL',

),

// ... repeated

),

'Owner' => array(

'DisplayName' => 'qcs::cam::uin/3210232098:uin/3210232098',

'ID' => 'qcs::cam::uin/3210232098:uin/3210232098',

),));

print_r($result);

} catch (\Exception $e) {

echo "$e\n";

}

返回结果示例

Array

(

[data:protected] => Array

(

[RequestId] => NWE3YzhiZTZfZDRiMjk0MGFfODMwXzJjODllYw==

)

)

getBucketACL

方法原型

// 获取文件列表

public Guzzle\Service\Resource\Model getBucketACL(array $args = array());

请求参数

字段名

类型

默认值

是否必填字段

描述

Bucket

string

bucket名称

请求示例

#getBucketACL

try {

$result = $cosClient->GetBucketAcl(array(

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

'Bucket' => 'testbucket-125000000',));

print_r($result);

} catch (\Exception $e) {

echo "$e\n";

}

返回结果示例

Array

(

[data:protected] => Array

(

[Owner] => Array

(

[ID] => qcs::cam::uin/3210232098:uin/3210232098

[DisplayName] => qcs::cam::uin/3210232098:uin/3210232098

)

[Grants] => Array

(

[0] => Array

(

[Grantee] => Array

(

[ID] => qcs::cam::uin/327874225:uin/327874225

[DisplayName] => qcs::cam::uin/327874225:uin/327874225

)

[Permission] => FULL_CONTROL

)

)

[RequestId] => NWE3YzhjMTRfYzdhMzNiMGFfYjdiOF8yYzZmMzU=

)

)

putObjectACL

方法原型

// 获取文件列表

public Guzzle\Service\Resource\Model putObjectACL(array $args = array());

请求参数

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

Key

上传文件的路径名,默认从 Bucket 开始

string

ACL

ACL权限控制

string

GrantRead

赋予被授权者读的权限。格式:id=" ",id=" ";当需要给子账户授权时,id="qcs::cam::uin/:uin/",当需要给根账户授权时,id="qcs::cam::uin/:uin/",例如:'id="qcs::cam::uin/123:uin/123", id="qcs::cam::uin/123:uin/456"'

string

GrantWrite

赋予被授权者写的权限。格式:id=" ",id=" ";当需要给子账户授权时,id="qcs::cam::uin/:uin/",当需要给根账户授权时,id="qcs::cam::uin/:uin/",例如:'id="qcs::cam::uin/123:uin/123", id="qcs::cam::uin/123:uin/456"'

string

GrantFullControl

赋予被授权者读写权限。格式:id=" ",id=" ";当需要给子账户授权时,id="qcs::cam::uin/:uin/",当需要给根账户授权时,id="qcs::cam::uin/:uin/",例如:'id="qcs::cam::uin/123:uin/123", id="qcs::cam::uin/123:uin/456"'

string

请求示例

#putObjectACL

try {

$result = $cosClient->PutObjectAcl(array(

'Bucket' => 'testbucket-1252448703',

'Key' => '111.txt',

'Grants' => array(

array(

'Grantee' => array(

'DisplayName' => 'qcs::cam::uin/327874225:uin/327874225',

'ID' => 'qcs::cam::uin/327874225:uin/327874225',

'Type' => 'CanonicalUser',

),

'Permission' => 'FULL_CONTROL',

),

// ... repeated

),

'Owner' => array(

'DisplayName' => 'qcs::cam::uin/3210232098:uin/3210232098',

'ID' => 'qcs::cam::uin/3210232098:uin/3210232098',

),));

print_r($result);

} catch (\Exception $e) {

echo "$e\n";

}

返回结果示例

Array

(

[data:protected] => Array

(

[RequestCharged] =>

[RequestId] => NWE3YzhjZDdfY2JhMzNiMGFfNjVhOV8yZDJhNjY=

)

)

getObjectACL

方法原型

// 获取文件列表

public Guzzle\Service\Resource\Model getObjectACL(array $args = array());

请求参数

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

Key

文件名称

string

请求示例

#getObjectACL

try {

$result = $cosClient->getObjectAcl(array(

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

'Bucket' => 'testbucket-125000000',

'Key' => '11'));

print_r($result);

} catch (\Exception $e) {

echo "$e\n";

}

返回结果示例

Array

(

[data:protected] => Array

(

[Owner] => Array

(

[ID] => qcs::cam::uin/3210232098:uin/3210232098

[DisplayName] => qcs::cam::uin/3210232098:uin/3210232098

)

[Grants] => Array

(

[0] => Array

(

[Grantee] => Array

(

[ID] => qcs::cam::uin/327874225:uin/327874225

[DisplayName] => qcs::cam::uin/327874225:uin/327874225

)

[Permission] => FULL_CONTROL

)

)

[RequestCharged] =>

[RequestId] => NWE3YzhjZDdfY2JhMzNiMGFfNjU5OF8yYzlkMmE=

)

)

putBucketCors

方法原型

// 获取文件列表

public Guzzle\Service\Resource\Model putBucketCors(array $args = array());

请求参数

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

CORSRules

CORS规则

array

AllowedMethods

允许的 HTTP 操作,枚举值:GET,PUT,HEAD,POST,DELETE

array

AllowedOrigins

允许的访问来源,支持通配符 * 格式为:协议://域名[:端口]如:http://www.qq.com

array

AllowedHeaders

在发送 OPTIONS 请求时告知服务端,接下来的请求可以使用哪些自定义的 HTTP 请求头部,支持通配符 *

array

ExposeHeaders

设置浏览器可以接收到的来自服务器端的自定义头部信息

array

MaxAgeSeconds

设置 OPTIONS 请求得到结果的有效期

string

ID

配置规则的 ID

string

请求示例

###putBucketCors

try {

$result = $cosClient->putBucketCors(array(

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

'Bucket' => 'testbucket-125000000',

// CORSRules is required

'CORSRules' => array(

array(

'AllowedHeaders' => array('*',),

// AllowedMethods is required

'AllowedMethods' => array('Put', ),

// AllowedOrigins is required

'AllowedOrigins' => array('*', ),

'ExposeHeaders' => array('*', ),

'MaxAgeSeconds' => 1,

),

// ... repeated

),

));

print_r($result);

} catch (\Exception $e) {

echo "$e\n";

}

返回结果示例

Array

(

[data:protected] => Array

(

[RequestCharged] =>

[RequestId] => NWE3YzhjZDdfY2JhMzNiMGFfNjVhOV8yZDJhNjY=

)

)

getBucketCors

方法原型

// 获取文件列表

public Guzzle\Service\Resource\Model getBucketCors(array $args = array());

请求参数

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

请求示例

#getBucketCors

try {

$result = $cosClient->getBucketCors(array(

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

'Bucket' => 'testbucket-125000000',

));

print_r($result);

} catch (\Exception $e) {

echo "$e\n";

}

返回结果示例

Array

(

[data:protected] => Array

(

[CORSRules] => Array

(

[0] => Array

(

[ID] => 1234

[AllowedHeaders] => Array

(

[0] => *

)

[AllowedMethods] => Array

(

[0] => PUT

)

[AllowedOrigins] => Array

(

[0] => http://www.qq.com

)

)

)

[RequestId] => NWE3YzhkMmRfMTdiMjk0MGFfNTQzZl8xNWUwMGU=

)

)

deleteBucketCors

方法原型

// 获取文件列表

public Guzzle\Service\Resource\Model deleteBucketCors(array $args = array());

请求参数

params (Object) : 参数列表

Bucket —— (String) : Bucket 名称

请求示例

#deleteBucketCors

try {

$result = $cosClient->deleteBucketCors(array(

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

'Bucket' => 'testbucket-125000000',

));

print_r($result);

} catch (\Exception $e) {

echo "$e\n";

}

返回结果示例

Array

(

[data:protected] => Array

(

[RequestCharged] =>

[RequestId] => NWE3YzhjZDdfY2JhMzNiMGFfNjVhOV8yZDJhNjY=

)

)

复制对象

方法原型

// 获取文件列表

public Guzzle\Service\Resource\Model copyObject(array $args = array());

请求参数

参数名称

描述

类型

是否必填字段

Bucket

Bucket 名称,由数字和小写字母以及中划线 "-" 构成

string

CopySource

复制来源

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

ServerSideEncryption

服务端加密方法

string

$args是包含以下字段的关联数组:

参数名称

描述

类型

是否必填字段

Bucket

Bucket 名称,由数字和小写字母以及中划线 "-" 构成

string

CopySource

复制来源

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

ServerSideEncryption

服务端加密方法

string

请求示例

#copyobject

#简单copy接口

try {

$result = $cosClient->copyObject(array(

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

'Bucket' => 'testbucket-125000000',

// CopySource is required

'CopySource' => 'lewzylu03-1252448703.cos.ap-guangzhou.myqcloud.com/tox.ini',

// Key is required

'Key' => 'string',

));

print_r($result);

} catch (\Exception $e) {

echo "$e\n";

}

#copy

#大于5g会自动使用分块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

方法原型

// 获取文件列表

public Guzzle\Service\Resource\Model putBucketLifecycle(array $args = array());

请求参数

参数名称

描述

类型

是否必填字段

Bucket

Bucket 名称,由数字和小写字母以及中划线 "-" 构成

string

Rules

设置对应的规则,包括 ID,Filter,Status,Expiration,Transition,NoncurrentVersionExpiration,NoncurrentVersionTransition,AbortIncompleteMultipartUpload

array

ID

配置规则的 ID

string

Filter

用于描述规则影响的 Object 集合

array

Status

设置 Rule 是否启用,可选值为 Enabled 或者 Disabled

string

Expiration

设置 Object 过期规则,可以指定天数 Days 或者指定日期 Date

array

Transition

设置 Object 转换存储类型规则,可以指定天数 Days 或者指定日期 Date,StorageClass 可选 Standard_IA, Nearline

array

请求示例

#putBucketLifecycle

try {

$result = $cosClient->putBucketLifecycle(array(

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

'Bucket' => 'testbucket-125000000',

// Rules is required

'Rules' => array(

array(

'Expiration' => array(

'Days' => 1,

),

'ID' => 'id1',

'Filter' => array(

'Prefix' => 'documents/'

),

// Status is required

'Status' => 'Enabled',

'Transitions' => array(

array(

'Days' => 200,

'StorageClass' => 'NEARLINE')),

// ... repeated

),

)));

print_r($result);

} catch (\Exception $e) {

echo "$e\n";

}

返回结果示例

Array

(

[data:protected] => Array

(

[RequestCharged] =>

[RequestId] => NWE3YzhjZDdfY2JhMzNiMGFfNjVhOV8yZDJhNjY=

)

)

getBucketLifecycle

方法原型

// 获取文件列表

public Guzzle\Service\Resource\Model getBucketLifecycle(array $args = array());

请求参数

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

请求示例

#getBucketLifecycle

try {

$result = $cosClient->getBucketLifecycle(array(

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

'Bucket' =>'testbucket-125000000',

));

print_r($result);

} catch (\Exception $e) {

echo "$e\n";

}

返回结果示例

Array

(

[data:protected] => Array

(

[Rules] => Array

(

[0] => Array

(

[ID] => id1

[Filter] => Array

(

[Prefix] => documents/

)

[Status] => Enabled

[Transition] => Array

(

[Days] => 200

[StorageClass] => NEARLINE

)

[Expiration] => Array

(

[Days] => 1000

)

)

)

[RequestId] => NWE3YzhlZjNfY2FhMzNiMGFfNDVkNF8yZDIxODE=

)

)

deleteBucketLifecycle

方法原型

// 获取文件列表

public Guzzle\Service\Resource\Model deleteBucketLifecycle(array $args = array());

请求参数

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

请求示例

#deleteBucketLifecycle

try {

$result = $cosClient->deleteBucketLifecycle(array(

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

'Bucket' =>'testbucket-125000000',

));

print_r($result);

} catch (\Exception $e) {

echo "$e\n";

}

返回结果示例

Array

(

[data:protected] => Array

(

[RequestCharged] =>

[RequestId] => NWE3YzhjZDdfY2JhMzNiMGFfNjVhOV8yZDJhNjY=

)

)

获得object下载url

获得object带签名的下载url

请求示例

//获得object的下载url

//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式

$bucket = 'testbucket-125000000';

$key = 'hello.txt';

$region = 'cn-south';

$url = "/{$key}";

$request = $cosClient->get($url);

$signedUrl = $cosClient->getObjectUrl($bucket, $key, '+10 minutes');

使用临时密钥

$cosClient = new Qcloud\Cos\Client(

array(

'region' => 'cn-south',

'timeout' => ,

'credentials'=> array(

'appId' => '',

'secretId' => '',

'secretKey' => '',

'token' => '')));

恢复归档文件

方法原型

// 恢复归档文件

public Guzzle\Service\Resource\Model deleteObject(array $args = array());

请求参数

$args是包含以下字段的关联数组:

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

Key

对象名称

string

Days

保存时间

integer

Tier

恢复类型

string

请求示例

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";

}

开启多版本

方法原型

// 开启多版本

public Guzzle\Service\Resource\Model putBucketVersioning(array $args = array());

请求参数

$args是包含以下字段的关联数组:

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

Status

多版本状态

string

请求示例

#putBucketVersioning

try {

$result = $cosClient->putBucketVersioning(

array('Bucket' => 'lewzylu02',

'Status' => 'Enabled')

);

print_r($result);

} catch (\Exception $e) {

echo "$e\n";

}

返回结果示例

Array

(

[data:protected] => Array

(

[RequestCharged] =>

[RequestId] => NWE3YzhjZDdfY2JhMzNiMGFfNjVhOV8yZDJhNjY=

)

)

获取bucket版本

方法原型

// 获取bucket版本

public Guzzle\Service\Resource\Model getBucketVersioning(array $args = array());

请求参数

$args是包含以下字段的关联数组:

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

请求示例

try {

$result = $cosClient->getBucketVersioning(

array('Bucket' => 'lewzylu02',)

);

print_r($result);

} catch (\Exception $e) {

echo "$e\n";

}

返回结果示例

Array

(

[data:protected] => Array

(

[Status] => Enabled

[RequestId] => NWE3YzhmZTVfNjIyNWI2NF80YzQ3XzJkNjU4NQ==

)

)

打印各个版本的文件列表

方法原型

// 打印各个版本的文件列表

public Guzzle\Service\Resource\Model listObjectVersions(array $args = array());

请求参数

$args是包含以下字段的关联数组:

参数名称

描述

类型

是否必填字段

Bucket

bucket名称

string

Delimiter

分隔符

string

Marker

标记

string

MaxKeys

最大对象个数

int

Prefix

前缀

string

请求示例

try {

$result = $cosClient->listObjectVersions(

array('Bucket' => 'lewzylu02',

'Prefix'=>'test1G')

);

print_r($result);

} catch (\Exception $e) {

echo "$e\n";

}

返回结果示例

Array

(

[data:protected] => Array

(

[Name] => lewzylu02-1252448703

[Prefix] => test1G

[KeyMarker] =>

[VersionIdMarker] =>

[MaxKeys] => 1000

[IsTruncated] =>

[Versions] => Array

(

[0] => Array

(

[Key] => test1G

[VersionId] => MTg0NDY3NDI1NTg1ODc4Nzk3NjI

[IsLatest] => 1

[LastModified] => 2018-01-05T03:07:51.000Z

[ETag] => "202cb962ac59075b964b07152d234b70"

[Size] => 3

[StorageClass] => STANDARD

[Owner] => Array

(

[UID] => 1252448703

)

)

[1] => Array

(

[Key] => test1G

[VersionId] => MTg0NDY3NDI1NTk0MzI3NDU3NTk

[IsLatest] =>

[LastModified] => 2017-12-26T08:26:50.000Z

[ETag] => "13ddf6552868644926ba606cd287106b-1"

[Size] => 5242880

[StorageClass] => STANDARD

[Owner] => Array

(

[UID] => 1252448703

)

)

[2] => Array

(

[Key] => test1G

[VersionId] => MTg0NDY3NDI1NTk0MzI3ODAzODc

[IsLatest] =>

[LastModified] => 2017-12-26T08:26:16.000Z

[ETag] => "3c86b7371340b2174b875fa7bcc0bd9a-1"

[Size] => 5242880

[StorageClass] => STANDARD

[Owner] => Array

(

[UID] => 1252448703

)

)

)

[RequestId] => NWE3YzkwMGFfMTliYjk0MGFfMWUwOWRfMmJlZWIx

)

)

ap接口 php_cos-php-sdk-v5接口文档相关推荐

  1. 在TCL网线接口的彩电上看pdf文档的电子书 845电脑的扫描电子电路图扫描仪图

    在TCL网线接口的彩电上看pdf文档的电子书  845电脑的扫描电子电路图扫描仪图 在TCL网线接口的彩电上看pdf文档的电子书  845电脑的扫描电子电路图扫描仪图 我加的电视是tcl48寸带网线接 ...

  2. VintaSoft Twain.NET SDK,实现扫描文档

    VintaSoft Twain.NET SDK,实现扫描文档 VintaSoft Twain.NET SDK是一个 .NET 库,可供希望通过 TWAIN 兼容(版本 1.x/2.x)设备和 .NET ...

  3. DTK Barcode Reader SDK,支持各种文档和图像格式

    DTK Barcode Reader SDK,支持各种文档和图像格式 DTK Barcode Reader SDK是一个跨平台实用程序,能够搜索和检测嵌入在您的照片或 PDF 文件中的条形码. 用户友 ...

  4. android新浪登录接口,新浪游戏AndroidSDK接入文档—服务端.md

    # SNG联运游戏平台接口文档ForCP(服务端) ## 1.用户接口 ### 1.1.用户信息校验接口(服务端) http://m.game.weibo.cn/api/sdk/user/check. ...

  5. 调用office web 365接口实现在线预览word文档,PDF,PPT

    我项目中是直接用iframe显示: <iframe id="iframe_src"  scrolling="auto"  width="100% ...

  6. 手机话费充值接口开发指南(含API文档,充值移动、联通、电信话费)

    平台上个星期上线了下载APP送随机话费的活动,下载后完成注册即可抽取1~10元话费红包.经过筛选,最终选择了互亿无线,第一有详细的计费明细,第二失败了确实有退款,第三有非常完整的接口文档和技术服务客服 ...

  7. LVDS,CML,LVPECL,VML之间接口电平转换(来自TI文档)

    在平时的工作中,经常会接触到各种差分电平的转换,网上也有很多这样的资料,但发现有些混乱,所以找了TI的这份文档进行翻译,一是系统的归类一下,二是自己也能通过这个来加深理解和学习.这个文档对于各个电平的 ...

  8. 微信sdk服务器支付文档,微信支付-普通下单开发者文档

    3.2. API接入(含示例代码) 本章节展示了如何使用微信支付服务端 SDK 快速接入小程序支付产品,完成与微信支付对接的部分. 注意: 文档中的代码示例是用来阐述 API 基本使用方法,代码中的示 ...

  9. 以太坊java接口_java以太坊库web3j文档

    通过java打包以太坊智能合约 Web3j可以自动打包智能合同代码,以便在不脱离JVM的情况下进行以太坊智能合同部署和交互. 要打包代码,需要先编译智能合同: $ solc .sol --bin -- ...

  10. Java 第三方sdk服务_文档中心 | QuickSDK——专业的手游第三方SDK接入服务平台,渠道SDK聚合,广告跟踪,客服,登录充值SDK...

    1.接入前项目检查(必接) 根据游戏接入后出现的问题,QuickSDK对游戏项目做以下几点要求: · AndroidManifest.xml中android:targetSdkVersion=&quo ...

最新文章

  1. 最长公共子序列_Java恶意序列化背后的历史和动机
  2. Python dataframe绘制饼图_【python可视化】:matplotlib:常见图表绘制——面积图、填图、饼图...
  3. P2730 魔板 Magic Squares (搜索)
  4. QML基础类型之point
  5. 使用verilog设计实现QR分解
  6. 02 | 健康之路 kubernetes(k8s) 实践之路 : 生产可用环境及验证
  7. 华为mate40会不会有鸿蒙系统,鸿蒙OS系统正式推送,拿华为Mate40更新后,发现了优缺点...
  8. [概率论与数理统计] 常用定义与公式
  9. Quartus 11.0 的AS 下载方式和JTAG下载jic文件的方式
  10. 大数据概述及电信大数据应用
  11. uml中活动图与流程图的区别
  12. 转载:【菜鸟专用】使用LaTeX轻松撰写精美个人简历
  13. excel数据可视化
  14. 手机测试中的ICCID是什么?
  15. 部署Guacamole远程控制桌面
  16. SSH远程控制与访问
  17. win32 python查找文字指定格式 win32com 定位word开始结束 相当于发送快捷键
  18. 一个领导发给下属的邮件,醍醐灌顶!
  19. 一个优秀的前端工程师年薪会有多少?
  20. IPv6邻居发现协议

热门文章

  1. 从苏宁电器到卡巴斯基第25篇:难忘的三年硕士时光 I
  2. 猛犸Winform分页控件
  3. python指纹识别_分享Python编写的网站组件指纹扫描工具.
  4. PICO《轻世界》体验:随心畅玩,洒脱创作,潜力无限
  5. 熟练知道eclipse中outline里各个图标的含义
  6. netterm连接linux虚拟机(转)
  7. ROS 通信机制(已整理)
  8. Eclipse 中WebService简单应用:手机归属地查询
  9. python-docx安装_python-docx的安装和使用
  10. 一页两个uEdit编辑器写法记录