有奖捉虫:云通信与企业服务文档专题,速来> HOT

简介

本文档提供关于查询对象元数据操作相关的 API 概览以及 SDK 示例代码。
API
操作名
操作描述
查询对象元数据
查询对象的元数据信息

查询对象元数据

功能说明

查询 Object 的 Meta 信息,包括用户自定义头部,Etag等对象元信息

示例代码

using COSXML.Model.Object;
using COSXML.Auth;
using System;
using COSXML;

namespace COSSnippet
{
public class HeadObjectModel {

private CosXml cosXml;

HeadObjectModel() {
CosXmlConfig config = new CosXmlConfig.Builder()
.SetRegion("COS_REGION") // 设置默认的区域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
.Build();

string secretId = "SECRET_ID"; // 云 API 密钥 SecretId, 获取 API 密钥请参照 https://console.cloud.tencent.com/cam/capi
string secretKey = "SECRET_KEY"; // 云 API 密钥 SecretKey, 获取 API 密钥请参照 https://console.cloud.tencent.com/cam/capi
long durationSecond = 600; //每次请求签名有效时长,单位为秒
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId,
secretKey, durationSecond);

this.cosXml = new CosXmlServer(config, qCloudCredentialProvider);
}

/// 获取对象信息
public void HeadObject()
{
//.cssg-snippet-body-start:[head-object]
try
{
// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.cloud.tencent.com/developer
string bucket = "examplebucket-1250000000";
string key = "exampleobject"; //对象键
HeadObjectRequest request = new HeadObjectRequest(bucket, key);
//执行请求
HeadObjectResult result = cosXml.HeadObject(request);
//请求成功
Console.WriteLine(result.GetResultInfo());
// 打印对象crc64
Console.WriteLine(result.crc64ecma);
// 打印对象eTag
Console.WriteLine(result.eTag);
}
catch (COSXML.CosException.CosClientException clientEx)
{
//请求失败
Console.WriteLine("CosClientException: " + clientEx);
}
catch (COSXML.CosException.CosServerException serverEx)
{
//请求失败
Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}

//.cssg-snippet-body-end
}
// .cssg-methods-pragma

static void Main(string[] args)
{
HeadObjectModel m = new HeadObjectModel();

/// 获取对象信息
m.HeadObject();
// .cssg-methods-pragma
}
}
}
说明
更多完整示例,请前往 GitHub 查看。