Static Website

Last updated: 2020-03-20 09:31:32

PDF

Note

This document provides an overview of API on static websites and sample SDK code.

API Operation name pedagogical operation
PUT Bucket website Setting up a Static Website Set Bucket's static website configuration
GET Bucket website Query static site configuration Query Bucket's static website configuration
DELETE Bucket website Delete static site configuration Delete Bucket's static website configuration

Setting up a Static Website

Function description

PUT Bucket website is used to configure a static website for Bucket.

Method prototype

public void setBucketWebsiteConfiguration(String bucketName, BucketWebsiteConfiguration configuration)
throws CosClientException, CosServiceException;
public void setBucketWebsiteConfiguration(SetBucketWebsiteConfigurationRequest setBucketWebsiteConfigurationRequest)
throws CosClientException, CosServiceException;

Request Sample

String bucketName = "examplebucket-1250000000";
BucketWebsiteConfiguration bucketWebsiteConfiguration = new BucketWebsiteConfiguration();
bucketWebsiteConfiguration.setIndexDocumentSuffix("index.html");
List<RoutingRule> routingRuleList = new ArrayList<RoutingRule>();
RoutingRule routingRule = new RoutingRule();
RoutingRuleCondition routingRuleCondition = new RoutingRuleCondition();
routingRuleCondition.setHttpErrorCodeReturnedEquals("404");
routingRule.setCondition(routingRuleCondition);
RedirectRule redirectRule = new RedirectRule();
redirectRule.setProtocol("https");
redirectRule.setReplaceKeyPrefixWith("404.html");
routingRule.setRedirect(redirectRule);
routingRuleList.add(routingRule);
bucketWebsiteConfiguration.setRoutingRules(routingRuleList);
cosclient.setBucketWebsiteConfiguration(bucketName, bucketWebsiteConfiguration);

Parameter description

Parameter name Description Type
SetBucketWebsiteConfigurationRequest Bucket static website setting request SetBucketWebsiteConfigurationRequest

Request member description:

Request member Setting method Description Type
BucketName Constructor or set method Set the Bucket of the static website in BucketName-APPID format. For more information, please see Naming convention String
Configuration Constructor or set method Bucket's static website configuration BucketWebsiteConfiguration

BucketWebsiteConfiguration member description:

Parameter name Description Type
IndexDocumentSuffix Index document String
ErrorDocument Error document String
RedirectAllRequestsTo Redirect all request configurations RedirectRule
RoutingRules Set redirection rules. Set a maximum of 100 RoutingRule List

RoutingRule member description:

Parameter name Description Type
Condition Specify the conditions under which redirection occurs. Only one prefix matching redirection and error code redirection can be specified. RoutingRuleCondition
Redirect Redirection rule RedirectRule

RoutingRuleCondition member description:

Parameter name Description Type
KeyPrefixEquals Specify the path to the prefix redirection RoutingRuleCondition
HttpErrorCodeReturnedEquals Specify redirect error code RedirectRule

RedirectRule member description:

Parameter name Description Type
Protocol Protocol who designated the redirection of the whole station. String
ReplaceKeyPrefixWith Replace the prefix that matches to the specified content, and the Conditon can only be set to KeyPrefixEquals. String
ReplaceKeyWith Replace the entire Key with the specified content String
HttpRedirectCode Protocol who designated the redirection of the whole station. String

Return result description

  • Success: no return value.
  • Failure: if an error occurs (such as Identity verification failure), an exception CosClientException or CosServiceException is thrown. For more information, please see Exception Handling .

Query static site configuration

Function description

GET Bucket website is used to query static website configuration information with Bucket and Associate.

Method prototype

public BucketWebsiteConfiguration getBucketWebsiteConfiguration(String bucketName)
            throws CosClientException, CosServiceException;

Request Sample

String bucketName = "examplebucket-1250000000";
BucketWebsiteConfiguration bucketWebsiteConfiguration = cosclient.getBucketWebsiteConfiguration(bucketName);

Parameter description

Parameter name Description Type
BucketName Query Bucket configured on a static website in BucketName-APPID format. For more information, please see Naming convention String

Return result description

  • Success: return BucketWebsiteConfiguration, containing Bucket's static website setting information.
  • Failure: if an error occurs (such as Identity verification failure), an exception CosClientException or CosServiceException is thrown. For more information, please see Exception Handling .

Delete static site configuration

Function description

DELETE Bucket website is used to delete the static website configuration in Bucket.

Method prototype

public void deleteBucketWebsiteConfiguration(String bucketName) throws CosClientException, CosServiceException;

Request Sample

String bucketName = "examplebucket-1250000000";
cosclient.deleteBucketWebsiteConfiguration(bucketName);

Parameter description

Parameter name Description Type
BucketName Bucket, whose static website configuration is deleted, is in BucketName-APPID format. For more information, please see Naming convention String

Return result description

  • Success: no return value.
  • Failure: if an error occurs (such as Identity verification failure), an exception CosClientException or CosServiceException is thrown. For more information, please see Exception Handling .