腾讯云oss技术文档 #
腾讯云OSS服务地址:https://console.cloud.tencent.com/cos5/bucket
官方SDK文档:https://cloud.tencent.com/document/product/436/32819
Sku Git:https://github.com/tencentyun/qcloud-sdk-dotnet.git
桶列表可新建存储桶
注:
权限管理-存储桶访问权限:公有读私有写,以便于外部服务可调用
安全管理-跨域访问CORS设置:
必要配置参数:
名称 | 描述 |
---|---|
APPID | 开发者访问 COS 服务时拥有的用户维度唯一资源标识,用以标识资源,可在 [API 密钥管理](https://console.cloud.tencent.com/capi" \t "https://cloud.tencent.com/document/product/436/_blank) 页面获取 |
SecretId | 开发者拥有的项目身份识别 ID,用于身份认证,可在 [API 密钥管理](https://console.cloud.tencent.com/capi" \t "https://cloud.tencent.com/document/product/436/_blank) 页面获取 |
SecretKey | 开发者拥有的项目身份密钥,可在 [API 密钥管理](https://console.cloud.tencent.com/capi" \t "https://cloud.tencent.com/document/product/436/_blank) 页面获取 |
Bucket | 存储桶,COS 中用于存储数据的容器。有关存储桶的进一步说明,请参见 [存储桶概述](https://cloud.tencent.com/document/product/436/13312" \t "https://cloud.tencent.com/document/product/436/_blank) 文档 |
BucketName-APPID | 存储桶名称格式,用户在使用 API、SDK 时,需要按照此格式填写存储桶名称。例如 examplebucket-1250000000,含义为该存储桶 examplebucket 归属于 APPID 为1250000000的用户 |
Object | 对象,COS 中存储的具体文件,是存储的基本实体 |
ObjectKey | 对象键,对象(Object)在存储桶(Bucket)中的唯一标识。有关对象与对象键的进一步说明,请参见 [对象概述](https://cloud.tencent.com/document/product/436/13324" \t "https://cloud.tencent.com/document/product/436/_blank) 文档 |
Region | 地域信息,枚举值可参见 [可用地域](https://cloud.tencent.com/document/product/436/6224" \t "https://cloud.tencent.com/document/product/436/_blank) 文档,例如:ap-beijing、ap-hongkong、eu-frankfurt 等 |
ACL | 访问控制列表(Access Control List),是指特定 Bucket 或 Object 的访问控制信息列表 |
CORS | 跨域资源共享(Cross-Origin Resource Sharing), 指发起请求的资源所在域不同于该请求所指向资源所在的域的 HTTP 请求 |
Multipart Uploads | 分块上传,腾讯云 COS 服务为上传文件提供的一种分块上传模式 |
Object Content | Object Content 是上传文件的二进制内容 |
注:API密钥文档:https://console.cloud.tencent.com/cam/capi
"UploadUrlImg": {
"Appid": "1252288782",//设置腾讯云账户的账户标识 APPID
"Bucket": "tcr-bailun1024-1252288782",//存储桶,格式:BucketName-APPID
"SecretId": "AKIDaS6VR7JYIkwrMYtrko1yc1GYZMrMdoeY",//云 API 密钥 SecretId
"SecretKey": "mJfkfL5Xv4za42C6nE8tNlt3JL7g3ABx",//云 API 密钥 SecretKey
"Region": "ap-guangzhou",// 存储桶所在地域
"AccessUrl": "https://tcr-bailun1024-1252288782.cos.ap-guangzhou.myqcloud.com"//存储桶访问域名
},
调用demo:
try
{
var newurl = await UploadUrlImgHelper.PutUploadUrlImgAsync(item.Image);
var dto = new UploadImgTask { Id = item.Id, Image = item.Image, Newimage = newurl, Status = 2 };
imglsit.Add(dto);
}
catch (Exception ex)
{
Console.WriteLine("发生异常重新推送数据:" + ex.Message);
error.Add(item);
}
public void TestUrl(string url)
{
//上传对象
var newurl = await UploadUrlImgHelper.PutUploadUrlImgAsync(item.Image);
//检索对象
UploadUrlImgHelper.SelectObject(url);
//删除对象
var dto1 = UploadUrlImgHelper.DeleteObject(url);
//批量删除
UploadUrlImgHelper.DeleteMultiObject(new List<string> { url});
}