Skip to content

Commit 0454f48

Browse files
authored
update sample files (#103)
1 parent 3023988 commit 0454f48

27 files changed

+835
-0
lines changed

sample/abortMultipartUpload.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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->abortMultipartUpload(array(
17+
'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID
18+
'Key' => 'exampleobject',
19+
'UploadId' => 'string',
20+
));
21+
// 请求成功
22+
print_r($result);
23+
} catch (\Exception $e) {
24+
// 请求失败
25+
echo($e);
26+
}
27+

sample/catchException.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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->getBucketAcl(array(
17+
'Bucket' => 'examplebucket-125000000' //格式:BucketName-APPID
18+
));
19+
// 请求成功
20+
print_r($result);
21+
} catch (\Exception $e) {
22+
// 请求失败
23+
$statusCode = $e->getStatusCode(); // 获取错误码
24+
$errorMessage = $e->getMessage(); // 获取错误信息
25+
$requestId = $e->getRequestId(); // 获取错误的requestId
26+
$errorCode = $e->getCosErrorCode(); // 获取错误名称
27+
$request = $e->getRequest(); // 获取完整的请求
28+
$response = $e->getResponse(); // 获取完整的响应
29+
}
30+

sample/completeMultipartUpload.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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->completeMultipartUpload(array(
17+
'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID
18+
'Key' => 'exampleobject',
19+
'UploadId' => 'string',
20+
'Parts' => array(
21+
array(
22+
'ETag' => 'string',
23+
'PartNumber' => integer,
24+
),
25+
array(
26+
'ETag' => 'string',
27+
'PartNumber' => integer,
28+
)),
29+
// ... repeated
30+
));
31+
// 请求成功
32+
print_r($result);
33+
} catch (\Exception $e) {
34+
// 请求失败
35+
echo($e);
36+
}
37+

sample/copyObject.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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->copyObject(array(
17+
'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID
18+
'Key' => 'exampleobject',
19+
'CopySource' => 'examplebucket2-125000000.cos.ap-guangzhou.myqcloud.com/exampleobject',
20+
'MetadataDirective' => 'Replaced',
21+
));
22+
// 请求成功
23+
print_r($result);
24+
} catch (\Exception $e) {
25+
// 请求失败
26+
echo($e);
27+
}
28+

sample/createBucket.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->createBucket(array(
17+
'Bucket' => 'examplebucket-125000000' //格式:BucketName-APPID
18+
));
19+
// 请求成功
20+
print_r($result);
21+
} catch (\Exception $e) {
22+
// 请求失败
23+
echo($e);
24+
}
25+

sample/createMultipartUpload.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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->createMultipartUpload(array(
17+
'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID
18+
'Key' => 'exampleobject',
19+
/*
20+
'CacheControl' => 'string',
21+
'ContentDisposition' => 'string',
22+
'ContentEncoding' => 'string',
23+
'ContentLanguage' => 'string',
24+
'ContentLength' => integer,
25+
'ContentType' => 'string',
26+
'Expires' => 'string',
27+
'Metadata' => array(
28+
'string' => 'string',
29+
),
30+
'StorageClass' => 'string'
31+
*/
32+
));
33+
// 请求成功
34+
print_r($result);
35+
} catch (\Exception $e) {
36+
// 请求失败
37+
echo($e);
38+
}
39+

sample/deleteBucket.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->deleteBucket(array(
17+
'Bucket' => 'examplebucket-125000000' //格式:BucketName-APPID
18+
));
19+
// 请求成功
20+
print_r($result);
21+
} catch (\Exception $e) {
22+
// 请求失败
23+
echo($e);
24+
}
25+

sample/deleteBucketCors.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->deleteBucketCors(array(
17+
'Bucket' => 'examplebucket-125000000' //格式:BucketName-APPID
18+
));
19+
// 请求成功
20+
print_r($result);
21+
} catch (\Exception $e) {
22+
// 请求失败
23+
echo($e);
24+
}
25+

sample/deleteBucketLifecycle.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->deleteBucketLifecycle(array(
17+
'Bucket' => 'examplebucket-125000000' //格式:BucketName-APPID
18+
));
19+
// 请求成功
20+
print_r($result);
21+
} catch (\Exception $e) {
22+
// 请求失败
23+
echo($e);
24+
}
25+

sample/deleteObject.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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->deleteObject(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+
}
26+

0 commit comments

Comments
 (0)