列举指定前缀的文件

列举包含指定前缀(prefix)的文件(Object),默认列举1000个文件,最多列举1000个文件。代码中需要引用"inspurcloud/oss/OssClient.h"类库,使用InspurCloud::OSS命名空间,并初始化账号信息AccessKeyId、AccessKeySecret、Endpoint,示例代码:

        //指定需要列举文件的存储桶及指定的前缀
        std::string BucketName = "yourBucketName";
        std::string keyPrefix = "yourkeyPrefix ";

        //初始化资源
        InitializeSdk();
        ClientConfiguration conf;
        OssClient client(Endpoint, AccessKeyId, AccessKeySecret, conf);

        //列举文件
        ListObjectsRequest request(BucketName);
        //指定前缀
        request.setPrefix(keyPrefix);
        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();