删除多版本对象
开发过程中,您有任何问题可以在github上提交issue,或者在华为云对象存储服务论坛中发帖求助。接口参考文档详细介绍了每个接口的参数和使用方法。
删除单个多版本对象
您可以通过ObsClient->deleteObject接口指定VersionId参数删除多版本对象,示例代码如下:
// 引入依赖库 require 'vendor/autoload.php'; // 使用源码安装时引入SDK代码库 // require 'obs-autoloader.php'; // 声明命名空间 use Obs\ObsClient; // 创建ObsClient实例 $obsClient = new ObsClient ( [ //推荐通过环境变量获取AKSK,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险。 //您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html 'key' => getenv('ACCESS_KEY_ID'), 'secret' => getenv('SECRET_ACCESS_KEY'), 'endpoint' => 'https://your-endpoint' ] ); $resp = $obsClient->deleteObject ( [ 'Bucket' => 'bucketname', 'Key' => 'objectname', 'VersionId' => 'versionid' ] ); printf ( "RequestId:%s\n", $resp ['RequestId'] );
批量删除多版本对象
您可以通过ObsClient->deleteObjects接口传入每个待删除对象的VersionId参数批量删除多版本对象,示例代码如下:
// 引入依赖库 require 'vendor/autoload.php'; // 使用源码安装时引入SDK代码库 // require 'obs-autoloader.php'; // 声明命名空间 use Obs\ObsClient; // 创建ObsClient实例 $obsClient = new ObsClient ( [ //推荐通过环境变量获取AKSK,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险。 //您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html 'key' => getenv('ACCESS_KEY_ID'), 'secret' => getenv('SECRET_ACCESS_KEY'), 'endpoint' => 'https://your-endpoint' ] ); $resp = $obsClient->deleteObjects ( [ 'Bucket' => 'bucketname', // 设置为verbose模式 'Quiet' => false, 'Objects' => [ [ 'Key' => 'objectname1', 'VersionId' => 'versionid1' ], [ 'Key' => 'objectname2', 'VersionId' => 'versionid2' ] ] ] ); printf ( "RequestId:%s\n", $resp ['RequestId'] ); // 获取删除成功的对象 printf ( "Deleteds:\n" ); foreach ( $resp ['Deleteds'] as $index => $deleted ) { printf ( "Deleteds[%d]", $index + 1 ); printf ( "Key:%s\n", $deleted ['Key'] ); printf ( "VersionId:%s\n", $deleted ['VersionId'] ); printf ( "DeleteMarker:%s\n", $deleted ['DeleteMarker'] ); printf ( "DeleteMarkerVersionId:%s\n", $deleted ['DeleteMarkerVersionId'] ); } // 获取删除失败的对象 printf ( "Errors:\n" ); foreach ( $resp ['Errors'] as $index => $error ) { printf ( "Errors[%d]", $index + 1 ); printf ( "Key:%s\n", $error ['Key'] ); printf ( "VersionId:%s\n", $$error ['VersionId'] ); printf ( "Code:%s\n", $error ['Code'] ); printf ( "Message:%s\n", $error ['Message'] ); }