|
2 | 2 |
|
3 | 3 | require(__DIR__ . DIRECTORY_SEPARATOR . 'cos-autoloader.php'); |
4 | 4 |
|
5 | | -$cosClient = new Qcloud\Cos\Client( |
6 | | - array( |
7 | | - 'region' => 'cn-north', |
8 | | - 'credentials'=> array( |
9 | | - 'appId' => '', |
10 | | - 'secretId' => '', |
11 | | - 'secretKey' => ''))); |
12 | | -#listBuckets |
13 | | -try { |
14 | | - $result = $cosClient->listBuckets(); |
15 | | - print_r($result); |
16 | | -} catch (\Exception $e) { |
17 | | - echo "$e\n"; |
18 | | -} |
19 | | - |
20 | | - |
| 5 | +$cosClient = new Qcloud\Cos\Client(array('region' => getenv('COS_REGION'), |
| 6 | + 'credentials'=> array( |
| 7 | + 'appId' => getenv('COS_APPID'), |
| 8 | + 'secretId' => getenv('COS_KEY'), |
| 9 | + 'secretKey' => getenv('COS_SECRET')))); |
| 10 | +//#listBuckets |
| 11 | +//try { |
| 12 | +// $result = $cosClient->listBuckets(); |
| 13 | +// print_r($result); |
| 14 | +//} catch (\Exception $e) { |
| 15 | +// echo "$e\n"; |
| 16 | +//} |
| 17 | +// |
| 18 | +// |
21 | 19 | #createBucket |
22 | 20 | try { |
23 | 21 | $result = $cosClient->createBucket(array('Bucket' => 'testbucket')); |
|
26 | 24 | echo "$e\n"; |
27 | 25 | } |
28 | 26 |
|
29 | | -#uploadbigfile |
30 | | -try { |
31 | | - $result = $cosClient->upload( |
32 | | - $bucket='testbucket', |
33 | | - '111.txt', |
34 | | - str_repeat('a', 5* 1024 * 1024)); |
35 | | - print_r($result); |
36 | | - } catch (\Exception $e) { |
37 | | - echo "$e\n"; |
38 | | -} |
39 | | - |
40 | | -#putObject |
| 27 | +//#uploadbigfile |
| 28 | +//try { |
| 29 | +// $result = $cosClient->upload( |
| 30 | +// $bucket='testbucket', |
| 31 | +// '111.txt', |
| 32 | +// str_repeat('a', 5* 1024 * 1024)); |
| 33 | +// print_r($result);1 |
| 34 | +// } catch (\Exception $e) { |
| 35 | +// echo "$e\n"; |
| 36 | +//} |
| 37 | +// |
| 38 | +//#putObject |
41 | 39 | try { |
42 | 40 | $result = $cosClient->putObject(array( |
43 | 41 | 'Bucket' => 'testbucket', |
44 | | - 'Key' => '111', |
| 42 | + 'Key' => '11', |
45 | 43 | 'Body' => 'Hello World!')); |
46 | 44 | print_r($result); |
47 | 45 | } catch (\Exception $e) { |
48 | 46 | echo "$e\n"; |
49 | 47 | } |
50 | | - |
51 | | -#getObject |
52 | | -try { |
53 | | - $result = $cosClient->getObject(array( |
54 | | - 'Bucket' => 'testbucket', |
55 | | - 'Key' => '111', |
56 | | - 'Body' => 'Hello World!')); |
57 | | - print_r($result); |
58 | | -} catch (\Exception $e) { |
59 | | - echo "$e\n"; |
60 | | -} |
61 | | - |
62 | | -#deleteObject |
63 | | -try { |
64 | | - $result = $cosClient->deleteObject(array( |
65 | | - 'Bucket' => 'testbucket', |
66 | | - 'Key' => '111')); |
67 | | - print_r($result); |
68 | | -} catch (\Exception $e) { |
69 | | - echo "$e\n"; |
70 | | -} |
71 | | - |
72 | | - |
73 | | -#deleteBucket |
| 48 | +// |
| 49 | +//#getObject |
| 50 | +//try { |
| 51 | +// $result = $cosClient->getObject(array( |
| 52 | +// 'Bucket' => 'testbucket', |
| 53 | +// 'Key' => '111')); |
| 54 | +// echo($result['Body']); |
| 55 | +//} catch (\Exception $e) { |
| 56 | +// echo "$e\n"; |
| 57 | +//} |
| 58 | +// |
| 59 | +//#deleteObject |
| 60 | +//try { |
| 61 | +// $result = $cosClient->deleteObject(array( |
| 62 | +// 'Bucket' => 'testbucket', |
| 63 | +// 'Key' => '111')); |
| 64 | +// print_r($result); |
| 65 | +//} catch (\Exception $e) { |
| 66 | +// echo "$e\n"; |
| 67 | +//} |
| 68 | +// |
| 69 | +// |
| 70 | +//#deleteBucket |
| 71 | +//try { |
| 72 | +// $result = $cosClient->deleteBucket(array( |
| 73 | +// 'Bucket' => 'testbucket')); |
| 74 | +// print_r($result); |
| 75 | +//} catch (\Exception $e) { |
| 76 | +// echo "$e\n"; |
| 77 | +//} |
| 78 | +// |
| 79 | +//#headObject |
| 80 | +//try { |
| 81 | +// $result = $cosClient->headObject(array( |
| 82 | +// 'Bucket' => 'testbucket', |
| 83 | +// 'Key' => 'hello.txt')); |
| 84 | +// print_r($result); |
| 85 | +//} catch (\Exception $e) { |
| 86 | +// echo "$e\n"; |
| 87 | +//} |
| 88 | +// |
| 89 | +//#listObjects |
| 90 | +//try { |
| 91 | +// $result = $cosClient->listObjects(array( |
| 92 | +// 'Bucket' => 'testbucket')); |
| 93 | +// print_r($result); |
| 94 | +//} catch (\Exception $e) { |
| 95 | +// echo "$e\n"; |
| 96 | +//} |
| 97 | +//#putObjectUrl |
| 98 | +//try { |
| 99 | +// $bucket = 'testbucket'; |
| 100 | +// $key = 'hello.txt'; |
| 101 | +// $region = 'cn-south'; |
| 102 | +// $url = "/{$key}"; |
| 103 | +// $request = $cosClient->get($url); |
| 104 | +// $signedUrl = $cosClient->getObjectUrl($bucket, $key, '+10 minutes'); |
| 105 | +// echo ($signedUrl); |
| 106 | +// |
| 107 | +//} catch (\Exception $e) { |
| 108 | +// echo "$e\n"; |
| 109 | +//} |
| 110 | +//#putBucketACL |
| 111 | +//try { |
| 112 | +// $result = $cosClient->PutBucketAcl(array( |
| 113 | +// 'Bucket' => 'testbucket', |
| 114 | +// 'Grants' => array( |
| 115 | +// array( |
| 116 | +// 'Grantee' => array( |
| 117 | +// 'DisplayName' => 'qcs::cam::uin/327874225:uin/327874225', |
| 118 | +// 'ID' => 'qcs::cam::uin/327874225:uin/327874225', |
| 119 | +// 'Type' => 'CanonicalUser', |
| 120 | +// ), |
| 121 | +// 'Permission' => 'FULL_CONTROL', |
| 122 | +// ), |
| 123 | +// // ... repeated |
| 124 | +// ), |
| 125 | +// 'Owner' => array( |
| 126 | +// 'DisplayName' => 'qcs::cam::uin/3210232098:uin/3210232098', |
| 127 | +// 'ID' => 'qcs::cam::uin/3210232098:uin/3210232098', |
| 128 | +// ),)); |
| 129 | +// print_r($result); |
| 130 | +//} catch (\Exception $e) { |
| 131 | +// echo "$e\n"; |
| 132 | +//} |
| 133 | +//#getBucketACL |
| 134 | +//try { |
| 135 | +// $result = $cosClient->GetBucketAcl(array( |
| 136 | +// 'Bucket' => 'testbucket',)); |
| 137 | +// print_r($result); |
| 138 | +//} catch (\Exception $e) { |
| 139 | +// echo "$e\n"; |
| 140 | +//} |
| 141 | +// |
| 142 | +#putObjectACL |
74 | 143 | try { |
75 | | - $result = $cosClient->deleteBucket(array( |
76 | | - 'Bucket' => 'testbucket')); |
77 | | - print_r($result); |
78 | | -} catch (\Exception $e) { |
79 | | - echo "$e\n"; |
80 | | -} |
81 | | - |
82 | | -#headObject |
83 | | -try { |
84 | | - $result = $cosClient->headObject(array( |
| 144 | + $result = $cosClient->PutBucketAcl(array( |
85 | 145 | 'Bucket' => 'testbucket', |
86 | | - 'Key' => 'hello.txt')); |
| 146 | + 'Grants' => array( |
| 147 | + array( |
| 148 | + 'Grantee' => array( |
| 149 | + 'DisplayName' => 'qcs::cam::uin/327874225:uin/327874225', |
| 150 | + 'ID' => 'qcs::cam::uin/327874225:uin/327874225', |
| 151 | + 'Type' => 'CanonicalUser', |
| 152 | + ), |
| 153 | + 'Permission' => 'FULL_CONTROL', |
| 154 | + ), |
| 155 | + // ... repeated |
| 156 | + ), |
| 157 | + 'Owner' => array( |
| 158 | + 'DisplayName' => 'qcs::cam::uin/3210232098:uin/3210232098', |
| 159 | + 'ID' => 'qcs::cam::uin/3210232098:uin/3210232098', |
| 160 | + ),)); |
87 | 161 | print_r($result); |
88 | 162 | } catch (\Exception $e) { |
89 | 163 | echo "$e\n"; |
90 | 164 | } |
91 | 165 |
|
92 | | -#listObjects |
93 | | -try { |
94 | | - $result = $cosClient->listObjects(array( |
95 | | - 'Bucket' => 'testbucket')); |
96 | | - print_r($result); |
97 | | -} catch (\Exception $e) { |
98 | | - echo "$e\n"; |
99 | | -} |
100 | | - |
101 | | - |
102 | | -#getObjectUrl |
103 | | -try { |
104 | | - $bucket = 'testbucket'; |
105 | | - $key = 'hello.txt'; |
106 | | - $region = 'cn-south'; |
107 | | - $url = "/{$key}"; |
108 | | - $request = $cosClient->get($url); |
109 | | - $signedUrl = $cosClient->getObjectUrl($bucket, $key, '+10 minutes'); |
110 | | - echo ($signedUrl); |
111 | | - |
112 | | -} catch (\Exception $e) { |
113 | | - echo "$e\n"; |
114 | | -} |
115 | | - |
116 | | - |
| 166 | +//#getObjectACL |
| 167 | +//try { |
| 168 | +// $result = $cosClient->getObjectAcl(array( |
| 169 | +// 'Bucket' => 'testbucket', |
| 170 | +// 'Key' => '11')); |
| 171 | +// print_r($result); |
| 172 | +//} catch (\Exception $e) { |
| 173 | +// echo "$e\n"; |
| 174 | +//} |
| 175 | +//#putBucketLifecycle |
| 176 | +//try { |
| 177 | +// $result = $cosClient->putBucketLifecycle(array( |
| 178 | +// // Bucket is required |
| 179 | +// 'Bucket' => 'lewzylu02', |
| 180 | +// // Rules is required |
| 181 | +// 'Rules' => array( |
| 182 | +// array( |
| 183 | +// 'Expiration' => array( |
| 184 | +// 'Days' => 1, |
| 185 | +// ), |
| 186 | +// 'ID' => 'id1', |
| 187 | +// 'Filter' => array( |
| 188 | +// 'Prefix' => 'documents/' |
| 189 | +// ), |
| 190 | +// // Status is required |
| 191 | +// 'Status' => 'Enabled', |
| 192 | +// 'Transition' => array( |
| 193 | +// 'Days' => 100, |
| 194 | +// 'StorageClass' => 'NEARLINE', |
| 195 | +// ), |
| 196 | +// // ... repeated |
| 197 | +// ), |
| 198 | +// ))); |
| 199 | +// print_r($result); |
| 200 | +//} catch (\Exception $e) { |
| 201 | +// echo "$e\n"; |
| 202 | +//} |
| 203 | +//#getBucketLifecycle |
| 204 | +//try { |
| 205 | +// $result = $cosClient->getBucketLifecycle(array( |
| 206 | +// // Bucket is required |
| 207 | +// 'Bucket' =>'lewzylu02', |
| 208 | +// )); |
| 209 | +// print_r($result); |
| 210 | +//} catch (\Exception $e) { |
| 211 | +// echo "$e\n"; |
| 212 | +//} |
| 213 | +// |
| 214 | +//#deleteBucketLifecycle |
| 215 | +//try { |
| 216 | +// $result = $cosClient->deleteBucketLifecycle(array( |
| 217 | +// // Bucket is required |
| 218 | +// 'Bucket' =>'lewzylu02', |
| 219 | +// )); |
| 220 | +// print_r($result); |
| 221 | +//} catch (\Exception $e) { |
| 222 | +// echo "$e\n"; |
| 223 | +//} |
| 224 | +//#putBucketCors |
| 225 | +//try { |
| 226 | +// $result = $cosClient->putBucketCors(array( |
| 227 | +// // Bucket is required |
| 228 | +// 'Bucket' => 'lewzylu02', |
| 229 | +// // CORSRules is required |
| 230 | +// 'CORSRules' => array( |
| 231 | +// array( |
| 232 | +// 'AllowedHeaders' => array('*',), |
| 233 | +// // AllowedMethods is required |
| 234 | +// 'AllowedMethods' => array('Put', ), |
| 235 | +// // AllowedOrigins is required |
| 236 | +// 'AllowedOrigins' => array('*', ), |
| 237 | +// 'ExposeHeaders' => array('*', ), |
| 238 | +// 'MaxAgeSeconds' => 1, |
| 239 | +// ), |
| 240 | +// // ... repeated |
| 241 | +// ), |
| 242 | +// )); |
| 243 | +// print_r($result); |
| 244 | +//} catch (\Exception $e) { |
| 245 | +// echo "$e\n"; |
| 246 | +//} |
| 247 | +//#getBucketCors |
| 248 | +//try { |
| 249 | +// $result = $cosClient->getBucketCors(array( |
| 250 | +// // Bucket is required |
| 251 | +// 'Bucket' => 'lewzylu02', |
| 252 | +// )); |
| 253 | +// print_r($result); |
| 254 | +//} catch (\Exception $e) { |
| 255 | +// echo "$e\n"; |
| 256 | +//} |
| 257 | +//#deleteBucketCors |
| 258 | +//try { |
| 259 | +// $result = $cosClient->deleteBucketCors(array( |
| 260 | +// // Bucket is required |
| 261 | +// 'Bucket' => 'lewzylu02', |
| 262 | +// )); |
| 263 | +// print_r($result); |
| 264 | +//} catch (\Exception $e) { |
| 265 | +// echo "$e\n"; |
| 266 | +//} |
| 267 | +//#copyobject |
| 268 | +//try { |
| 269 | +// $result = $cosClient->copyObject(array( |
| 270 | +// // Bucket is required |
| 271 | +// 'Bucket' => 'lewzylu02', |
| 272 | +// // CopySource is required |
| 273 | +// 'CopySource' => 'lewzylu03-1252448703.cos.ap-guangzhou.myqcloud.com/tox.ini', |
| 274 | +// // Key is required |
| 275 | +// 'Key' => 'string', |
| 276 | +// )); |
| 277 | +// print_r($result); |
| 278 | +//} catch (\Exception $e) { |
| 279 | +// echo "$e\n"; |
| 280 | +//} |
0 commit comments