public Task <string> GetBlobUrl(string containerName, string blobName) { var preSignatureStruct = new PreSignatureStruct(); preSignatureStruct.appid = _tcConfig.AppId; //腾讯云账号 APPID preSignatureStruct.region = _tcConfig.Region; //存储桶地域 preSignatureStruct.bucket = _tcConfig.BucketName; //存储桶 preSignatureStruct.key = $"{containerName}/{blobName}"; //对象键 preSignatureStruct.httpMethod = "PUT"; //HTTP 请求方法 preSignatureStruct.isHttps = true; //生成 HTTPS 请求 URL preSignatureStruct.signDurationSecond = 600; //请求签名时间为 600s preSignatureStruct.headers = null; //签名中需要校验的 header preSignatureStruct.queryParameters = null; //签名中需要校验的 URL 中请求参数 var url = _cosXmlServer.GenerateSignURL(preSignatureStruct); return(Task.FromResult(url)); }
//临时密钥预签名请求示例-下载 public string DownGetUrl() { try { CosXmlConfig config = new CosXmlConfig.Builder() .SetConnectionTimeoutMs(60000) //设置连接超时时间,单位 毫秒 ,默认 45000ms .SetReadWriteTimeoutMs(40000) //设置读写超时时间,单位 毫秒 ,默认 45000ms .IsHttps(true) //设置默认 https 请求 .SetAppid(AppID) //设置腾讯云账户的账户标识 APPID .SetRegion(AppTong) //设置一个默认的存储桶地域 .SetDebugLog(true) //显示日志 .Build(); //创建 CosXmlConfig 对象 string secretId = SecretId; //"云 API 密钥 SecretId"; string secretKey = SecretKey; //"云 API 密钥 SecretKey"; long durationSecond = 600; //secretKey 有效时长,单位为 秒 QCloudCredentialProvider cosCredentialProvider = new DefaultQCloudCredentialProvider(secretId, secretKey, durationSecond); CosXmlServer cosXml = new CosXmlServer(config, cosCredentialProvider); PreSignatureStruct preSignatureStruct = new PreSignatureStruct(); preSignatureStruct.appid = AppID; //腾讯云账号 appid preSignatureStruct.region = AppTong; //存储桶地域 preSignatureStruct.bucket = Cct; //存储桶 preSignatureStruct.key = Dxj; //对象键 preSignatureStruct.httpMethod = "GET"; //http 请求方法 preSignatureStruct.isHttps = true; //生成 https 请求URL preSignatureStruct.signDurationSecond = 600; //请求签名时间为 600s preSignatureStruct.headers = null; //签名中需要校验的header preSignatureStruct.queryParameters = null; //签名中需要校验的URL中请求参数 return(cosXml.GenerateSignURL(preSignatureStruct)); //载请求预签名 URL (使用永久密钥方式计算的签名 URL ) #region 临时密钥下载 ////使用临时密钥初始化 CosXml //CosXmlConfig config = new CosXmlConfig.Builder() //.SetConnectionTimeoutMs(60000) //设置连接超时时间,单位 毫秒 ,默认 45000ms //.SetReadWriteTimeoutMs(40000) //设置读写超时时间,单位 毫秒 ,默认 45000ms //.IsHttps(true) //设置默认 https 请求 //.SetAppid(AppID) //设置腾讯云账户的账户标识 APPID //.SetRegion(AppTong) //设置一个默认的存储桶地域 //.SetDebugLog(true) //显示日志 //.Build(); //创建 CosXmlConfig 对象 //string tmpSecretId = SecretId; //"临时密钥 SecretId"; //string tmpSecretKey = SecretKey; //"临时密钥 SecretKey"; //string tmpToken = Token; //"临时密钥 token"; //long tmpExpireTime = ConvertDateTimeInt(DateTime.Now);//临时密钥有效截止时间 //QCloudCredentialProvider cosCredentialProvider = new DefaultSessionQCloudCredentialProvider(tmpSecretId, tmpSecretKey, tmpExpireTime, tmpToken); //CosXmlServer cosXml = new CosXmlServer(config, cosCredentialProvider); //PreSignatureStruct preSignatureStruct = new PreSignatureStruct(); //preSignatureStruct.appid = AppID;//腾讯云账号 appid //preSignatureStruct.region = AppTong; //存储桶地域 //preSignatureStruct.bucket = Cct; //存储桶 //preSignatureStruct.key = Dxj; //对象键 //preSignatureStruct.httpMethod = "GET"; //http 请求方法 //preSignatureStruct.isHttps = true; //生成 https 请求URL //preSignatureStruct.signDurationSecond = 600; //请求签名时间为 600s //preSignatureStruct.headers = null;//签名中需要校验的header //preSignatureStruct.queryParameters = null; //签名中需要校验的URL中请求参数 //return cosXml.GenerateSignURL(preSignatureStruct); //载请求预签名 URL (使用临时密钥方式计算的签名 URL ) #endregion 临时密钥下载 } catch (Exception) { return(""); } }