简介
本文档提供关于生成对象访问 URL 的示例代码。
生成对象访问链接
当对象 ACL 属性设置为“公有读”时,可以通过以下 SDK 接口生成的 URL 直接访问对象(仅支持生成 COS 默认源站域名的 URL)。
try{// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.cloud.tencent.com/developerstring bucket = "examplebucket-1250000000";string key = "exampleobject"; //对象键// 生成公有读URLstring requestURL = cosXml.GetObjectUrl(bucket, key);//请求成功Console.WriteLine(requestURL);}catch (COSXML.CosException.CosClientException clientEx){//请求失败Console.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){//请求失败Console.WriteLine("CosServerException: " + serverEx.GetInfo());}
说明