API | Operation Name | Operation Description |
Setting CORS Configuration | Set the cross-origin access permission of a bucket. | |
Querying CORS Configuration | Query the cross-origin access configuration information of a bucket. | |
Deleting CORS Configuration | Delete the cross-origin access configuration information of a bucket. |
// A bucket name consists of bucketname-appid. You must include the appid. You can view bucket names in the COS console. https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";PutBucketCORSRequest putBucketCORSRequest = new PutBucketCORSRequest(bucket);CORSConfiguration.CORSRule corsRule = new CORSConfiguration.CORSRule();// Configure the rule IDcorsRule.id = "123";// Allowed origins, which support the wildcard *. The format is: protocol://domain[:port]corsRule.allowedOrigin = "https://cloud.tencent.com";// Set the validity period for results returned by OPTIONS requestscorsRule.maxAgeSeconds = 5000;List<String> methods = new LinkedList<>();methods.add("PUT");methods.add("POST");methods.add("GET");// Allowed HTTP operations, for example: GET, PUT, HEAD, POST, DELETEcorsRule.allowedMethod = methods;List<String> headers = new LinkedList<>();headers.add("host");headers.add("content-type");// When sending an OPTIONS request, inform the server of the HTTP request headers that can be used in subsequent requests. These headers support the wildcard *.corsRule.allowedHeader = headers;List<String> exposeHeaders = new LinkedList<>();exposeHeaders.add("x-cos-meta-1");// Set custom headers from the server that the browser can receivecorsRule.exposeHeader = exposeHeaders;putBucketCORSRequest.addCORSRule(corsRule);cosXmlService.putBucketCORSAsync(putBucketCORSRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {PutBucketCORSResult putBucketCORSResult = (PutBucketCORSResult) result;}// If you call the API using kotlin, note that the exception in the callback method must be nullable. Otherwise, the onFail method will not be called, as follows:// The type of clientException is CosXmlClientException?, and the type of serviceException is CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
// A bucket name consists of bucketname-appid. You must include the appid. You can view bucket names in the COS console. https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";GetBucketCORSRequest getBucketCORSRequest = new GetBucketCORSRequest(bucket);cosXmlService.getBucketCORSAsync(getBucketCORSRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetBucketCORSResult getBucketCORSResult = (GetBucketCORSResult) result;}// If you call the API using kotlin, note that the exception in the callback method must be nullable. Otherwise, the onFail method will not be called, as follows:// The type of clientException is CosXmlClientException?, and the type of serviceException is CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
// A bucket name consists of bucketname-appid. You must include the appid. You can view bucket names in the COS console. https://console.tencentcloud.com/cos5/bucketString bucket = "examplebucket-1250000000";DeleteBucketCORSRequest deleteBucketCORSRequest =new DeleteBucketCORSRequest(bucket);cosXmlService.deleteBucketCORSAsync(deleteBucketCORSRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {DeleteBucketCORSResult deleteBucketCORSResult =(DeleteBucketCORSResult) result;}// If you call the API using kotlin, note that the exception in the callback method must be nullable. Otherwise, the onFail method will not be called, as follows:// The type of clientException is CosXmlClientException?, and the type of serviceException is CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
Esta página foi útil?
Você também pode entrar em contato com a Equipe de vendas ou Enviar um tíquete em caso de ajuda.
comentários