API | Operation | Description |
Setting a static website | Configures a static website for a bucket | |
Querying a static website configuration | Queries the static website configuration of a bucket | |
Deleting a static website configuration | Deletes the static website configuration of a bucket |
CosResult CosAPI::PutBucketWebsite(const PutBucketWebsiteReq& request,PutBucketWebsiteResp* response);
qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);std::string bucket_name = "examplebucket-1250000000";qcloud_cos::PutBucketWebsiteReq req(bucket_name);qcloud_cos::PutBucketWebsiteResp resp;req.SetSuffix("index.xml"); // Requiredreq.SetProtocol("https");req.SetKey("Error.html");// Set a maximum of 100 redirection rules.// Set the first rule.qcloud_cos::RoutingRule routerule1;qcloud_cos::Condition temp_condtion1;temp_condtion1.SetHttpErrorCodeReturnedEquals(404);// Required. Defaults to `404`.routerule1.SetCondition(temp_condtion1);qcloud_cos::Redirect temp_redirect1;temp_redirect1.SetProtocol("https");temp_redirect1.SetReplaceKeyWith("404.htmp");routerule1.SetRedirect(temp_redirect1);// Set the second rule.qcloud_cos::RoutingRule routerule2;qcloud_cos::Condition temp_condtion2;temp_condtion2.SetHttpErrorCodeReturnedEquals(403);// Required. Defaults to `404`.routerule2.SetCondition(temp_condtion2);qcloud_cos::Redirect temp_redirect2;temp_redirect2.SetProtocol("https");temp_redirect2.SetReplaceKeyWith("403.htmp");routerule2.SetRedirect(temp_redirect2);// Set the third rule.qcloud_cos::RoutingRule routerule3;qcloud_cos::Condition temp_condtion3;temp_condtion3.SetKeyPrefixEquals("img/");temp_condtion3.SetHttpErrorCodeReturnedEquals(402);routerule3.SetCondition(temp_condtion3);qcloud_cos::Redirect temp_redirect3;temp_redirect3.SetProtocol("https");temp_redirect3.SetReplaceKeyWith("401.htmp");routerule3.SetRedirect(temp_redirect3);// Set the fourth rule.qcloud_cos::RoutingRule routerule4;qcloud_cos::Condition temp_condtion4;temp_condtion4.SetKeyPrefixEquals("img1/");routerule4.SetCondition(temp_condtion4);qcloud_cos::Redirect temp_redirect4;temp_redirect4.SetProtocol("https");temp_redirect4.SetReplaceKeyPrefixWith("402.htmp");routerule4.SetRedirect(temp_redirect4);req.AddRoutingRule(routerule1);req.AddRoutingRule(routerule2);req.AddRoutingRule(routerule3);req.AddRoutingRule(routerule4);qcloud_cos::CosResult result = cos.PutBucketWebsite(req, &resp);if (result.IsSucc()) {// Request successful} else {// Request failed. You can call the CosResult member functions to output the error information, such as requestID.}
Parameter | Description | Type | Required |
req | Request of the PutBucketWebsite operation | PutBucketWebsiteReq | Yes |
resp | Response of the PutBucketWebsite operation | PutBucketWebsiteResp | Yes |
CosResult CosAPI::GetBucketWebsite(const GetBucketWebsiteReq& request, GetBucketWebsiteResp* response);
qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);std::string bucket_name = "examplebucket-1250000000";qcloud_cos::GetBucketWebsiteReq req(bucket_name);qcloud_cos::GetBucketWebsiteResp resp;qcloud_cos::CosResult result = cos.GetBucketWebsite(req, &resp);if (result.IsSucc()) {// Request successful. You can obtain the static website configuration via `resp`.} else {// Request failed. You can call the CosResult member functions to output the error information, such as requestID.}
Parameter | Description | Type | Required |
req | Request of the GetBucketWebsite operation | GetBucketWebsiteReq | Yes |
resp | Response of the GetBucketWebsite operation | GetBucketWebsiteResp | Yes |
GetBucketWebsiteResp
provides the following method to obtain the static website configuration:std::vector<RoutingRule> GetRoutingRules() const;
RoutingRule
, please refer to the SDK header files.CosResult CosAPI::DeleteBucketWebsite(const DeleteBucketWebsiteReq& request, DeleteBucketWebsiteResp* response);
qcloud_cos::CosConfig config("./config.json");qcloud_cos::CosAPI cos(config);std::string bucket_name = "examplebucket-1250000000";qcloud_cos::DeleteBucketWebsiteReq req(bucket_name);qcloud_cos::DeleteBucketWebsiteResp resp;qcloud_cos::CosResult result = cos.DeleteBucketWebsite(req, &resp);if (result.IsSucc()) {// Request successful} else {// Request failed. You can call the CosResult member functions to output the error information, such as requestID.}
Parameter | Description | Type | Required |
req | Request of the DeleteBucketWebsite operation | DeleteBucketWebsiteReq | Yes |
resp | Response of the DeleteBucketWebsite operation | DeleteBucketWebsiteResp | Yes |
Was this page helpful?