如果仅需要文件中的部分数据,您可以使用范围下载,下载指定范围内的数据。

以下代码用于范围下载:

#include <alibabacloud/oss/OssClient.h>
using namespace AlibabaCloud::OSS;

int main(void)
{
     /* 初始化OSS账号信息 */
    std::string AccessKeyId = "yourAccessKeyId";
    std::string AccessKeySecret = "yourAccessKeySecret";
    std::string Endpoint = "yourEndpoint";
    std::string BucketName = "yourBucketName";
    std::string ObjectName = "yourObectName ";

     /* 初始化网络等资源 */
    InitializeSdk();

    ClientConfiguration conf;
    OssClient client(Endpoint, AccessKeyId, AccessKeySecret,  conf );

    /* 获取文件 */
    GetObjectRequest request(BucketName,  ObjectName);
    /* 设置下载范围 */
    request.setRange(0, 1);
    auto outcome = client.GetObject(request);

    if (!outcome.isSuccess ()) {    
        /* 异常处理 */
        std::cout << "getObject fail" <<
        ",code:" << outcome.error().Code() <<
        ",message:" << outcome.error().Message() <<
        ",requestId:" << outcome.error().RequestId() << std::endl;
        ShutdownSdk();
         return -1;  
    }

    /* 释放网络等资源 */
    ShutdownSdk();
    return 0;
}