批量删除指定前缀的文件
⚠ 请您谨慎使用删除操作,文件一旦删除将无法恢复。
批量删除指定前缀的文件。代码中需要引用"inspurcloud/oss/OssClient.h"类库,使用InspurCloud::OSS命名空间,并初始化账号信息AccessKeyId、AccessKeySecret、Endpoint,示例代码:
//需要指定文件所在的桶以及前缀(prefix)
std::string BucketName = "yourBucketName";
std::string keyPrefix = "yourkeyPrefix ";
//初始化网络等资源
InitializeSdk();
ClientConfiguration conf;
OssClient client(Endpoint, AccessKeyId, AccessKeySecret, conf);
//删除文件
DeleteObjectsRequest request(BucketName);
auto outcome = client.DeleteObjects(request, keyPrefix);
//处理结果
if (!outcome.isSuccess()) {
std::cout << "DeleteObjects fail" << std::endl;
std::cout << "error code:" << outcome.error().Code() << std::endl;
std::cout << "error message:" << outcome.error().Message() << std::endl;
std::cout << "requestId:" << outcome.error().RequestId() << std::endl;
ShutdownSdk();
return -1;
}
else {
std::cout << "DeleteObject Success!" << std::endl;
}
//释放资源
ShutdownSdk();