try{PreSignatureStruct preSignatureStruct = new PreSignatureStruct();// APPID 获取参考 https://console.tencentcloud.com/developerpreSignatureStruct.appid = "1250000000";// 存储桶所在地域, COS 地域的简称请参照 https://www.tencentcloud.com/document/product/436/6224?from_cn_redirect=1preSignatureStruct.region = "COS_REGION";// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developerpreSignatureStruct.bucket = "examplebucket-1250000000";preSignatureStruct.key = "exampleobject"; //对象键preSignatureStruct.httpMethod = "GET"; //HTTP 请求方法preSignatureStruct.isHttps = true; //生成 HTTPS 请求 URLpreSignatureStruct.signDurationSecond = 600; //请求签名时间为600spreSignatureStruct.headers = null;//签名中需要校验的 headerpreSignatureStruct.queryParameters = null; //签名中需要校验的 URL 中请求参数string requestSignURL = cosXml.GenerateSignURL(preSignatureStruct);//下载请求预签名 URL (使用永久密钥方式计算的签名 URL)string localDir = System.IO.Path.GetTempPath();//本地文件夹string localFileName = "my-local-temp-file"; //指定本地保存的文件名GetObjectRequest request = new GetObjectRequest(null, null, localDir, localFileName);//设置下载请求预签名 URLrequest.RequestURLWithSign = requestSignURL;//设置进度回调request.SetCosProgressCallback(delegate (long completed, long total){Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));});//执行请求GetObjectResult result = cosXml.GetObject(request);//请求成功Console.WriteLine(result.GetResultInfo());}catch (COSXML.CosException.CosClientException clientEx){//请求失败Console.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){//请求失败Console.WriteLine("CosServerException: " + serverEx.GetInfo());}
try{PreSignatureStruct preSignatureStruct = new PreSignatureStruct();// APPID 获取参考 https://console.tencentcloud.com/developerpreSignatureStruct.appid = "1250000000";// 存储桶所在地域, COS 地域的简称请参照 https://www.tencentcloud.com/document/product/436/6224?from_cn_redirect=1preSignatureStruct.region = "COS_REGION";// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developerpreSignatureStruct.bucket = "examplebucket-1250000000";preSignatureStruct.key = "exampleobject"; //对象键preSignatureStruct.httpMethod = "PUT"; //HTTP 请求方法preSignatureStruct.isHttps = true; //生成 HTTPS 请求 URLpreSignatureStruct.signDurationSecond = 600; //请求签名时间为 600spreSignatureStruct.headers = null;//签名中需要校验的 headerpreSignatureStruct.queryParameters = null; //签名中需要校验的 URL 中请求参数//上传预签名 URL (使用永久密钥方式计算的签名 URL)string requestSignURL = cosXml.GenerateSignURL(preSignatureStruct);string srcPath = @"temp-source-file";//本地文件绝对路径PutObjectRequest request = new PutObjectRequest(null, null, srcPath);//设置上传请求预签名 URLrequest.RequestURLWithSign = requestSignURL;//设置进度回调request.SetCosProgressCallback(delegate (long completed, long total){Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));});//执行请求PutObjectResult result = cosXml.PutObject(request);//请求成功Console.WriteLine(result.GetResultInfo());}catch (COSXML.CosException.CosClientException clientEx){//请求失败Console.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){//请求失败Console.WriteLine("CosServerException: " + serverEx.GetInfo());}
try{PreSignatureStruct preSignatureStruct = new PreSignatureStruct();// APPID 获取参考 https://console.tencentcloud.com/developerpreSignatureStruct.appid = "1250000000";// 存储桶所在地域, COS 地域的简称请参照 https://www.tencentcloud.com/document/product/436/6224?from_cn_redirect=1preSignatureStruct.region = "COS_REGION";// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developerpreSignatureStruct.bucket = "examplebucket-1250000000";preSignatureStruct.key = "exampleobject"; //对象键preSignatureStruct.httpMethod = "GET"; //HTTP 请求方法preSignatureStruct.isHttps = true; //生成 HTTPS 请求 URLpreSignatureStruct.signDurationSecond = 600; //请求签名时间为600spreSignatureStruct.signHost = true; // 请求中签入Host,建议开启,能够有效防止越权请求,需要注意,开启后实际请求也需要携带Host请求头preSignatureStruct.headers = null;//签名中需要校验的 headerpreSignatureStruct.queryParameters = null; //签名中需要校验的 URL 中请求参数string requestSignURL = cosXml.GenerateSignURL(preSignatureStruct);Console.WriteLine("requestUrl is:" + requestSignURL);//下载请求预签名 URL (使用永久密钥方式计算的签名 URL)string localDir = System.IO.Path.GetTempPath();//本地文件夹string localFileName = "my-local-temp-file"; //指定本地保存的文件名GetObjectRequest request = new GetObjectRequest(null, null, localDir, localFileName);//设置下载请求预签名 URLrequest.RequestURLWithSign = requestSignURL;//设置进度回调request.SetCosProgressCallback(delegate (long completed, long total){Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));});//执行请求GetObjectResult result = cosXml.GetObject(request);//请求成功Console.WriteLine(result.GetResultInfo());}catch (COSXML.CosException.CosClientException clientEx){//请求失败Console.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){//请求失败Console.WriteLine("CosServerException: " + serverEx.GetInfo());}
try{PreSignatureStruct preSignatureStruct = new PreSignatureStruct();// APPID 获取参考 https://console.tencentcloud.com/developerpreSignatureStruct.appid = "1250000000";// 存储桶所在地域, COS 地域的简称请参照 https://www.tencentcloud.com/document/product/436/6224?from_cn_redirect=1preSignatureStruct.region = "COS_REGION";// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.tencentcloud.com/developerpreSignatureStruct.bucket = "examplebucket-1250000000";preSignatureStruct.key = "exampleobject"; //对象键preSignatureStruct.httpMethod = "GET"; //HTTP 请求方法preSignatureStruct.isHttps = true; //生成 HTTPS 请求 URLpreSignatureStruct.signDurationSecond = 600; //请求签名时间为600spreSignatureStruct.signHost = true; // 请求中签入Host,建议开启,能够有效防止越权请求,需要注意,开启后实际请求也需要携带Host请求头preSignatureStruct.headers = null; // 签名中需要校验的 headerstring ci_params = "imageMogr2/thumbnail/!50p";preSignatureStruct.queryParameters = new Dictionary<string, string>(); // 签名中需要校验的 URL 中请求参数,以请求万象图片处理为例preSignatureStruct.queryParameters.Add(ci_params, null);string requestSignURL = cosXml.GenerateSignURL(preSignatureStruct);Console.WriteLine("requestUrl is:" + requestSignURL);//下载请求预签名 URL (使用永久密钥方式计算的签名 URL)string localDir = System.IO.Path.GetTempPath();//本地文件夹string localFileName = "my-local-temp-file"; //指定本地保存的文件名GetObjectRequest request = new GetObjectRequest(null, null, localDir, localFileName);//设置下载请求预签名 URLrequest.RequestURLWithSign = requestSignURL;//设置进度回调request.SetCosProgressCallback(delegate (long completed, long total){Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));});//执行请求GetObjectResult result = cosXml.GetObject(request);//请求成功Console.WriteLine(result.GetResultInfo());}catch (COSXML.CosException.CosClientException clientEx){//请求失败Console.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){//请求失败Console.WriteLine("CosServerException: " + serverEx.GetInfo());}
本页内容是否解决了您的问题?