API | 操作名 | 操作描述 |
删除单个对象 | 在存储桶中删除指定对象 | |
删除多个对象 | 在存储桶中批量删除对象 |
public Guzzle\\Service\\Resource\\Model deleteObject(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->deleteObject(array('Bucket' => 'examplebucket-1250000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket'Key' => 'exampleobject' //若多路径则写为folder/exampleobject,不要在第一层带/,否则删除会失败));// 请求成功print_r($result);} catch (\\Exception $e) {// 请求失败echo($e);}
<?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->deleteObject(array('Bucket' => 'examplebucket-1250000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket'Key' => 'exampleobject', //若多路径则写为folder/exampleobject,不要在第一层带/,否则删除会失败'VersionId' => 'exampleVersionId' //存储桶未开启版本控制时请勿携带此参数));// 请求成功print_r($result);} catch (\\Exception $e) {// 请求失败echo($e);}
参数名称 | 类型 | 描述 | 是否必填 |
Bucket | String | 存储桶名称,格式:BucketName-APPID | 是 |
Key | String | 此处的 Key 为对象键,对象键是对象在存储桶中的唯一标识。例如,在对象的访问域名 examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg 中,对象键为doc/pic.jpg | 是 |
VersionId | String | 删除文件的版本号 | 否 |
public Guzzle\\Service\\Resource\\Model deleteObjects(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->deleteObjects(array('Bucket' => 'examplebucket-1250000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket'Objects' => array(array('Key' => 'exampleobject', //若多路径则写为folder/exampleobject,不要在第一层带/,否则删除会失败),// ... repeated),));// 请求成功print_r($result);} catch (\\Exception $e) {// 请求失败echo($e);}
<?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->deleteObjects(array('Bucket' => 'examplebucket-1250000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket'Objects' => array(array('Key' => 'exampleobject', //若多路径则写为folder/exampleobject,不要在第一层带/,否则删除会失败'VersionId' => 'string' //存储桶未开启版本控制时请勿携带此参数),// ... repeated),));// 请求成功print_r($result);} catch (\\Exception $e) {// 请求失败echo($e);}
public Guzzle\\Service\\Resource\\Model deleteObjects(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)));$cos_prefix = "cos/folder";$nextMarker = '';$isTruncated = true;while ( $isTruncated ) {try {$result = $cosClient->listObjects(['Bucket' => 'examplebucket-1250000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket'Delimiter' => '','EncodingType' => 'url','Marker' => $nextMarker,'Prefix' => $cos_prefix,'MaxKeys' => 1000]);$isTruncated = $result['IsTruncated'];$nextMarker = $result['NextMarker'];foreach ( $result['Contents'] as $content ) {$cos_file_path = $content['Key'];$local_file_path = $content['Key'];// 按照需求自定义拼接下载路径try {$cosClient->deleteObject(array('Bucket' => 'examplebucket-1250000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucket'Key' => $cos_file_path,));echo ( $cos_file_path . "\\n" );} catch ( \\Exception $e ) {echo( $e );}}} catch ( \\Exception $e ) {echo( $e );}}
参数名称 | 类型 | 描述 | 是否必填 |
Bucket | String | 存储桶名称,格式:BucketName-APPID | 是 |
Objects | Array | 删除对象列表 | 是 |
Object | Array | 删除的对象 | 是 |
Key | String | 此处的 Key 为对象键,对象键是对象在存储桶中的唯一标识。例如,在对象的访问域名 examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg 中,对象键为doc/pic.jpg | 是 |
VersionId | String | 删除文件的版本号 | 否 |
Guzzle\\Service\\Resource\\Model Object([structure:protected] =>[data:protected] => Array([Deleted] => Array([0] => Array([Key] => exampleobject1))[Errors] => Array([0] => Array([Key] => exampleobject2[Code] =>[Message] =>))[RequestId] => NWNhZWYzYWNfMTlhYTk0MGFfNGRjX2MzZTVhOQ==))
参数名称 | 类型 | 描述 | 父节点 |
Deleted | Array | 成功删除的对象的列表 | 无 |
Errors | Array | 失败删除的对象的列表 | 无 |
Key | String | 对象键 | Deleted/Errors |
Code | String | 失败错误码 | Errors |
Message | String | 失败错误信息 | Errors |
本页内容是否解决了您的问题?