API | Operation | Description |
Setting CORS configuration | Sets the CORS permissions of bucket | |
Querying CORS configuration | Queries the CORS configuration of a bucket | |
Deleting CORS configuration | Deletes the CORS configuration of a bucket |
try{// Bucket name in the format of `BucketName-APPID`. You can get APPID by referring to https://console.tencentcloud.com/developer.string bucket = "examplebucket-1250000000";PutBucketCORSRequest request = new PutBucketCORSRequest(bucket);// Set CORS configurationCOSXML.Model.Tag.CORSConfiguration.CORSRule corsRule =new COSXML.Model.Tag.CORSConfiguration.CORSRule();corsRule.id = "corsconfigureId";corsRule.maxAgeSeconds = 6000;corsRule.allowedOrigins = new List<string>();corsRule.allowedOrigins.Add("http://cloud.tencent.com");corsRule.allowedMethods = new List<string>();corsRule.allowedMethods.Add("PUT");corsRule.allowedHeaders = new List<string>();corsRule.allowedHeaders.Add("Host");corsRule.exposeHeaders = new List<string>();corsRule.exposeHeaders.Add("x-cos-meta-x1");request.SetCORSRule(corsRule);// Execute the requestPutBucketCORSResult result = cosXml.PutBucketCORS(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{// Bucket name in the format of `BucketName-APPID`. You can get APPID by referring to https://console.tencentcloud.com/developer.string bucket = "examplebucket-1250000000";GetBucketCORSRequest request = new GetBucketCORSRequest(bucket);// Execute the requestGetBucketCORSResult result = cosXml.GetBucketCORS(request);// Bucket CORS configurationCORSConfiguration conf = result.corsConfiguration;}catch (COSXML.CosException.CosClientException clientEx){// Request failedConsole.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){// Request failedConsole.WriteLine("CosServerException: " + serverEx.GetInfo());}
try{// Bucket name in the format of `BucketName-APPID`. You can get APPID by referring to https://console.tencentcloud.com/developer.string bucket = "examplebucket-1250000000";DeleteBucketCORSRequest request = new DeleteBucketCORSRequest(bucket);// Execute the requestDeleteBucketCORSResult result = cosXml.DeleteBucketCORS(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?