API | 操作名 | 操作描述 |
删除存储桶 | 删除指定账号下的空存储桶 |
public Guzzle\\Service\\Resource\\Model deleteBucket(array $args = array());
<?phprequire dirname(__FILE__) . '/../vendor/autoload.php';$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.tencentcloud.com/cam/capi$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.tencentcloud.com/cam/capi$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.tencentcloud.com/cos5/bucket$cosClient = new Qcloud\\Cos\\Client(array('region' => $region,'schema' => 'https', //协议头部,默认为http'credentials'=> array('secretId' => $secretId ,'secretKey' => $secretKey)));try {$result = $cosClient->deleteBucket(array('Bucket' => 'examplebucket-125000000' //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket));// 请求成功print_r($result);} catch (\\Exception $e) {// 请求失败echo($e);}
参数名称 | 父节点 | 描述 | 类型 |
Bucket | 无 | 存储桶名称,格式:BucketName-APPID | String |
public Guzzle\\Service\\Resource\\Model deleteBuckets(array $args = array());
<?phprequire dirname(__FILE__) . '/../vendor/autoload.php';$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.tencentcloud.com/cam/capi$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.tencentcloud.com/cam/capi$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.tencentcloud.com/cos5/bucket$cosClient = new Qcloud\\Cos\\Client(array('region' => $region,'schema' => 'https', //协议头部,默认为http'credentials'=> array('secretId' => $secretId ,'secretKey' => $secretKey)));try {//列出所有buckets$buckets = $cosClient->listBuckets();//若bucket列表不为空则进行删除逻辑,先删除对象,再判断是否有上传的任务进行删除,最后删除桶//可以在foreach中添加exclude逻辑(如建立一个需保留的桶数组),保留无需保留的桶if (!empty($buckets['Buckets'][0])) {foreach ($buckets['Buckets'][0]['Bucket'] as $key => $value) {$result = $cosClient->listObjects(array('Bucket' => $value['Name']));if (isset($result['Contents'])) {foreach ($result['Contents'] as $content) {$cosClient->deleteObject(array('Bucket' => $value['Name'], 'Key' => $content['Key']));}}while(True){$result = $cosClient->ListMultipartUploads(array('Bucket' => $value['Name']));if ($result['Uploads'] == array()) {break;}foreach ($result['Uploads'] as $upload) {try {$cosClient->AbortMultipartUpload(array('Bucket' => $value['Name'],'Key' => $upload['Key'],'UploadId' => $upload['UploadId']));} catch (\\Exception $e) {print_r($e);}}}$cosClient->deleteBucket(array('Bucket' => $value['Name']));}}print_r('DELETE ALL BUCKETS SUCCEED!');} catch (\\Exception $e) {// 请求失败echo($e);}
参数名称 | 父节点 | 描述 | 类型 |
Bucket | 无 | 存储桶名称,格式:BucketName-APPID | String |
本页内容是否解决了您的问题?