下载文件到内存
实现下载指定文件(Object)到内存。代码中需要引用"inspurcloud/oss/OssClient.h"类库,使用InspurCloud::OSS命名空间,并初始化账号信息AccessKeyId、AccessKeySecret、Endpoint,示例代码:
//指定目标文件所存在的桶以及目标文件(Object)名称
std::string BucketName = "yourBucketName";
std::string ObjectName = "yourObjectName";
//初始化资源
InitializeSdk();
ClientConfiguration conf;
OssClient client(Endpoint, AccessKeyId, AccessKeySecret, conf);
//获取文件到内存
GetObjectRequest request(BucketName, ObjectName);
auto outcome = client.GetObject(request);
//处理结果
if (outcome.isSuccess()) {
std::cout << "getObjectToBuffer success"<<std::endl;
std::cout << "Content-Length:" << outcome.result().Metadata().ContentLength() << std::endl;
std::string content;
while (std::getline(*(outcome.result().Content()), content)) {
std::cout << content << std::endl << std::endl;
}
}
//异常处理
else {
std::cout << "getObjectToBuffer 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();