Skip to content
Bitzsoft.Integrationsbitzsoft.integrations

Reference

腾讯云 COS

腾讯云 COS 文件存储包的 TencentCosOptions 配置字段、AppId/Region 鉴权与使用示例。

Last updated

包信息

属性
NuGet 包Bitzsoft.Integrations.FileStorage.Tencent
Provider IDtencent
鉴权AppId + SecretId + SecretKey

配置字段(TencentCosOptions)

字段类型必填默认值说明
AppIdstring腾讯云 AppId
SecretIdstring腾讯云 SecretId
SecretKeystring腾讯云 SecretKey
RegionstringCOS 区域(如 ap-guangzhou
DefaultBucketNamestring默认存储桶名称(不含 AppId 后缀)
HttpClientNamestringHttpClient 名称
UploadUrlExpirationint3600上传地址过期时间(秒)
DownloadUrlExpirationint43200下载地址过期时间(秒)

配置示例

{
"FileStorage": {
"Tencent": {
"AppId": "1234567890",
"SecretId": "AKIDxxxxxxxx",
"SecretKey": "your-secret-key",
"Region": "ap-guangzhou",
"DefaultBucketName": "my-bucket"
}
}
}

DI 注册

builder.Services.AddBitzsoftTencentCosFileStorage(builder.Configuration.GetSection("FileStorage:Tencent"));

使用示例

public class CosService(IFileStore store)
{
public async Task<DirectUploadParam> GetUploadUrlAsync(string fileName)
{
return await store.GenerateUploadUrlAsync(fileName);
}
}

已知限制

  • DefaultBucketName 不含 AppId 后缀(腾讯桶名格式为 bucket-name-AppId,实现自动拼接)。
  • 下载地址过期时间默认 43200 秒(12 小时),比上传的 1 小时长。

相关

100%

滚轮或按钮缩放 · 放大后拖动画面 · 双击切换 100% / 200%