删除多个文件
⚠ 请您谨慎使用删除操作,文件一旦删除将无法恢复。
实现批量删除存储桶内文件。代码中需要引用"inspurcloud/oss/OssClient.h"类库,使用InspurCloud::OSS命名空间,并初始化账号信息AccessKeyId、AccessKeySecret、Endpoint,示例代码:
//需要指定文件所在的桶名称以及文件名,当删除n个文件时,需要指定n个ObjectName,从ObjectName1-ObjectNamen,依次添加删除。
std::string BucketName = "yourBucketName";
std::string ObjectName1 = "yourObjectName1";
std::string ObjectName2 = "yourObjectName2";
//初始化资源
InitializeSdk();
ClientConfiguration conf;
OssClient client(Endpoint, AccessKeyId, AccessKeySecret, conf);
DeleteObjectsRequest request(BucketName);
//添加要删除文件的文件名
request.addKey(ObjectName1);
request.addKey(ObjectName2);
//删除文件
auto outcome = client.DeleteObjects(request);
//处理结果
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();