获取文件元信息
实现获取文件元信息(Object Meta),包括HTTP header和自定义元信息。代码中需要引用"inspurcloud/oss/OssClient.h"类库,使用InspurCloud::OSS命名空间,并初始化账号信息AccessKeyId、AccessKeySecret、Endpoint,示例代码:
//指定目标文件所存在的桶以及目标文件名称
std::string BucketName = "yourBucketName";
std::string ObjectName = "yourObjectName";
//初始化网络等资源
InitializeSdk();
ClientConfiguration conf;
OssClient client(Endpoint, AccessKeyId, AccessKeySecret, conf);
//获取文件的全部元信息
auto outcome = client.HeadObject(BucketName, ObjectName);
//处理结果
if (outcome.isSuccess()) {
auto headMeta = outcome.result();
std::cout << "headMeta success" << std::endl;
std::cout << "ContentType:" << headMeta.ContentType() << std::endl;
std::cout << "ContentLength:" << headMeta.ContentLength() << std::endl;
std::cout << "CacheControl:" << headMeta.CacheControl() << std::endl;
}
// 异常处理
else {
std::cout << "HeadObject 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();