列举指定个数的文件
列举存储桶内指定个数的文件(Object),默认列举1000个文件,最多列举1000个文件。代码中需要引用"inspurcloud/oss/OssClient.h"类库,使用InspurCloud::OSS命名空间,并初始化账号信息AccessKeyId、AccessKeySecret、Endpoint,示例代码:
//指定需要列举文件的存储桶
std::string BucketName = "yourBucketName";
//初始化资源
InitializeSdk();
ClientConfiguration conf;
OssClient client(Endpoint, AccessKeyId, AccessKeySecret, conf) ;
//列举文件
ListObjectsRequest request(BucketName);
request.setMaxKeys(200); //设置列举个数,最大为1000
auto outcome = client.ListObjects(request);
//处理结果
if (outcome.isSuccess()) {
for (const auto& object : outcome.result().ObjectSummarys()) {
std::cout << "object name:" << object.Key() <<",size:" << object.Size() <<
",lastmodify time:" << object.LastModified() << std::endl;
}
}
//异常处理
else {
std::cout << "ListObjects 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;
}
//释放资源
ShutdownSdk();