try{PreSignatureStruct preSignatureStruct = new PreSignatureStruct();// For details about how to get the APPID, visit https://console.tencentcloud.com/developer.preSignatureStruct.appid = "1250000000";// Bucket region. For the abbreviations of COS regions, visit https://www.tencentcloud.com/zh/document/product/436/6224.preSignatureStruct.region = "COS_REGION";// Bucket name in the format of `BucketName-APPID`. You can get APPID by referring to https://console.tencentcloud.com/developer.preSignatureStruct.bucket = "examplebucket-1250000000";preSignatureStruct.key = "exampleobject"; // Object keypreSignatureStruct.httpMethod = "GET"; // HTTP request methodpreSignatureStruct.isHttps = true; // Generate an HTTPS request URLpreSignatureStruct.signDurationSecond = 600; // Request signature duration is 600spreSignatureStruct.headers = null;// Header in the signature that needs to be verifiedpreSignatureStruct.queryParameters = null; // URL request parameters in the signature that need to be verifiedstring requestSignURL = cosXml.GenerateSignURL(preSignatureStruct);// Pre-signed URL for download request (signed URL calculated with the permanent key method)string localDir = System.IO.Path.GetTempPath();// Local file directorystring localFileName = "my-local-temp-file"; // Filename of the local fileGetObjectRequest request = new GetObjectRequest(null, null, localDir, localFileName);// Set the pre-signed URL for download requestsrequest.RequestURLWithSign = requestSignURL;// Set the progress callbackrequest.SetCosProgressCallback(delegate (long completed, long total){Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));});// Execute the requestGetObjectResult result = cosXml.GetObject(request);// Request succeededConsole.WriteLine(result.GetResultInfo());}catch (COSXML.CosException.CosClientException clientEx){// Request failedConsole.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){// Request failedConsole.WriteLine("CosServerException: " + serverEx.GetInfo());}
try{PreSignatureStruct preSignatureStruct = new PreSignatureStruct();// For details about how to get the APPID, visit https://console.tencentcloud.com/developer.preSignatureStruct.appid = "1250000000";// Bucket region. For the abbreviations of COS regions, visit https://www.tencentcloud.com/zh/document/product/436/6224.preSignatureStruct.region = "COS_REGION";// Bucket name in the format of `BucketName-APPID`. You can get APPID by referring to https://console.tencentcloud.com/developer.preSignatureStruct.bucket = "examplebucket-1250000000";preSignatureStruct.key = "exampleobject"; // Object keypreSignatureStruct.httpMethod = "PUT"; // HTTP request methodpreSignatureStruct.isHttps = true; // Generate an HTTPS request URLpreSignatureStruct.signDurationSecond = 600; // Request signature duration is 600spreSignatureStruct.headers = null;// Header in the signature that needs to be verifiedpreSignatureStruct.queryParameters = null; // URL request parameters in the signature that need to be verified// Pre-signed URL for upload (signed URL calculated with the permanent key method)string requestSignURL = cosXml.GenerateSignURL(preSignatureStruct);string srcPath = @"temp-source-file";// Absolute path of the local filePutObjectRequest request = new PutObjectRequest(null, null, srcPath);// Set the pre-signed URL for the upload requestrequest.RequestURLWithSign = requestSignURL;// Set the progress callbackrequest.SetCosProgressCallback(delegate (long completed, long total){Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));});// Execute the requestPutObjectResult result = cosXml.PutObject(request);// Request succeededConsole.WriteLine(result.GetResultInfo());}catch (COSXML.CosException.CosClientException clientEx){// Request failedConsole.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){// Request failedConsole.WriteLine("CosServerException: " + serverEx.GetInfo());}
Host
in the signaturetry{PreSignatureStruct preSignatureStruct = new PreSignatureStruct();// For details about how to get the APPID, visit https://console.tencentcloud.com/developer.preSignatureStruct.appid = "1250000000";// Bucket region. For the abbreviations of COS regions, visit https://www.tencentcloud.com/zh/document/product/436/6224.preSignatureStruct.region = "COS_REGION";// Bucket name in the format of `BucketName-APPID`. You can get APPID by referring to https://console.tencentcloud.com/developer.preSignatureStruct.bucket = "examplebucket-1250000000";preSignatureStruct.key = "exampleobject"; // Object keypreSignatureStruct.httpMethod = "GET"; // HTTP request methodpreSignatureStruct.isHttps = true; // Generate an HTTPS request URLpreSignatureStruct.signDurationSecond = 600; // Request signature duration is 600spreSignatureStruct.signHost = true; // Whether to include `Host` in the request signature. It is recommended to include `Host` in the signature to avoid unauthorized requests. Note that if `Host` is included in the signature, the `Host` request header must also be carried in the actual request.preSignatureStruct.headers = null;// Header in the signature that needs to be verifiedpreSignatureStruct.queryParameters = null; // URL request parameters in the signature that need to be verifiedstring requestSignURL = cosXml.GenerateSignURL(preSignatureStruct);Console.WriteLine("requestUrl is:" + requestSignURL);// Pre-signed URL for download request (signed URL calculated with the permanent key method)string localDir = System.IO.Path.GetTempPath();// Local file directorystring localFileName = "my-local-temp-file"; // Filename of the local fileGetObjectRequest request = new GetObjectRequest(null, null, localDir, localFileName);// Set the pre-signed URL for download requestsrequest.RequestURLWithSign = requestSignURL;// Set the progress callbackrequest.SetCosProgressCallback(delegate (long completed, long total){Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));});// Execute the requestGetObjectResult result = cosXml.GetObject(request);// Request succeededConsole.WriteLine(result.GetResultInfo());}catch (COSXML.CosException.CosClientException clientEx){// Request failedConsole.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){// Request failedConsole.WriteLine("CosServerException: " + serverEx.GetInfo());}
try{PreSignatureStruct preSignatureStruct = new PreSignatureStruct();// For details about how to get the APPID, visit https://console.tencentcloud.com/developer.preSignatureStruct.appid = "1250000000";// Bucket region. For the abbreviations of COS regions, visit https://www.tencentcloud.com/zh/document/product/436/6224.preSignatureStruct.region = "COS_REGION";// Bucket name in the format of `BucketName-APPID`. You can get APPID by referring to https://console.tencentcloud.com/developer.preSignatureStruct.bucket = "examplebucket-1250000000";preSignatureStruct.key = "exampleobject"; // Object keypreSignatureStruct.httpMethod = "GET"; // HTTP request methodpreSignatureStruct.isHttps = true; // Generate an HTTPS request URLpreSignatureStruct.signDurationSecond = 600; // Request signature duration is 600spreSignatureStruct.signHost = true; // Whether to include `Host` in the request signature. It is recommended to include `Host` in the signature to avoid unauthorized requests. Note that if `Host` is included in the signature, the `Host` request header must also be carried in the actual request.preSignatureStruct.headers = null;// Headers in the signature that need to be verifiedstring ci_params = "imageMogr2/thumbnail/!50p";preSignatureStruct.queryParameters = new Dictionary<string, string>(); // Request parameters in the URL in the signature that need to be verified. Take a CI image processing request as an example.preSignatureStruct.queryParameters.Add(ci_params, null);string requestSignURL = cosXml.GenerateSignURL(preSignatureStruct);Console.WriteLine("requestUrl is:" + requestSignURL);// Pre-signed URL for download request (signed URL calculated with the permanent key method)string localDir = System.IO.Path.GetTempPath();// Local file directorystring localFileName = "my-local-temp-file"; // Filename of the local fileGetObjectRequest request = new GetObjectRequest(null, null, localDir, localFileName);// Set the pre-signed URL for download requestsrequest.RequestURLWithSign = requestSignURL;// Set the progress callbackrequest.SetCosProgressCallback(delegate (long completed, long total){Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));});// Execute the requestGetObjectResult result = cosXml.GetObject(request);// Request succeededConsole.WriteLine(result.GetResultInfo());}catch (COSXML.CosException.CosClientException clientEx){// Request failedConsole.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){// Request failedConsole.WriteLine("CosServerException: " + serverEx.GetInfo());}
Apakah halaman ini membantu?