API | Operation | Description |
Setting a static website configuration | 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 |
// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket.NSString *bucket = @"examplebucket-1250000000";NSString *indexDocumentSuffix = @"index.html";NSString *errorDocKey = @"error.html";NSString *derPro = @"https";int errorCode = 451;NSString * replaceKeyPrefixWith = @"404.html";QCloudPutBucketWebsiteRequest *putReq = [QCloudPutBucketWebsiteRequest new];putReq.bucket = bucket;QCloudWebsiteConfiguration *config = [QCloudWebsiteConfiguration new];QCloudWebsiteIndexDocument *indexDocument = [QCloudWebsiteIndexDocument new];// Specify the object key suffix of the index document. For example, if index.html is specified, then when the root directory of the bucket is accessed,// the content of index.html will automatically be returned; when the article/ directory is accessed, the content of article/index.html will automatically be returned.indexDocument.suffix = indexDocumentSuffix;// Index document configurationconfig.indexDocument = indexDocument;// Error document configurationQCloudWebisteErrorDocument *errDocument = [QCloudWebisteErrorDocument new];errDocument.key = errorDocKey;// Specify the object key of the general error document. When an error occurs and no error code in the redirect rule is hit for redirect, the content of this object key will be returnedconfig.errorDocument = errDocument;// Configuration for redirecting all requestsQCloudWebsiteRedirectAllRequestsTo *redir = [QCloudWebsiteRedirectAllRequestsTo new];redir.protocol = derPro;// Specify the target protocol for redirecting all requests; only HTTPS can be usedconfig.redirectAllRequestsTo = redir;// Configuration for a single redirect ruleQCloudWebsiteRoutingRule *rule = [QCloudWebsiteRoutingRule new];// Conditions for the redirect ruleQCloudWebsiteCondition *contition = [QCloudWebsiteCondition new];contition.httpErrorCodeReturnedEquals = errorCode;rule.condition = contition;// Specific redirect destination of the redirect ruleQCloudWebsiteRedirect *webRe = [QCloudWebsiteRedirect new];webRe.protocol = derPro;// Specify the object key of the redirect destination specified in the rule. The prefix part matched in the original request will be replaced.// This can be set only if the Condition is set to KeyPrefixEqualswebRe.replaceKeyPrefixWith = replaceKeyPrefixWith;rule.redirect = webRe;QCloudWebsiteRoutingRules *routingRules = [QCloudWebsiteRoutingRules new];routingRules.routingRule = @[rule];// Redirect rule configuration. Up to 100 RoutingRule values can be setconfig.rules = routingRules;putReq.websiteConfiguration = config;[putReq setFinishBlock:^(id outputObject, NSError *error) {// outputObject contains all the HTTP response headersNSDictionary* info = (NSDictionary *) outputObject;}];[[QCloudCOSXMLService defaultCOSXML] PutBucketWebsite:putReq];
let req = QCloudPutBucketWebsiteRequest.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket.req.bucket = "examplebucket-1250000000";let indexDocumentSuffix = "index.html";let errorDocKey = "error.html";let errorCode = 451;let replaceKeyPrefixWith = "404.html";let config = QCloudWebsiteConfiguration.init();let indexDocument = QCloudWebsiteIndexDocument.init();// Specify the object key suffix of the index document. For example, if index.html is specified, then when the root directory of the bucket is accessed,// the content of index.html will automatically be returned; when the article/ directory is accessed, the content of article/index.html will automatically be returned.indexDocument.suffix = indexDocumentSuffix;// Index document configurationconfig.indexDocument = indexDocument;// Error document configurationlet errDocument = QCloudWebisteErrorDocument.init();errDocument.key = errorDocKey;// Specify the object key of the general error document. When an error occurs and no error code in the redirect rule is hit for redirect, the content of this object key will be returnedconfig.errorDocument = errDocument;// Configuration for redirecting all requestslet redir = QCloudWebsiteRedirectAllRequestsTo.init();// Specify the target protocol for redirecting all requests; only HTTPS can be usedredir.protocol = "https";config.redirectAllRequestsTo = redir;// Configuration for a single redirect rulelet rule = QCloudWebsiteRoutingRule.init();// Conditions for the redirect rulelet contition = QCloudWebsiteCondition.init();contition.httpErrorCodeReturnedEquals = Int32(errorCode);rule.condition = contition;// Specific redirect destination of the redirect rulelet webRe = QCloudWebsiteRedirect.init();webRe.protocol = "https";// Specify the object key of the redirect destination specified in the rule. The prefix part matched in the original request will be replaced.// This can be set only if the Condition is set to KeyPrefixEqualswebRe.replaceKeyPrefixWith = replaceKeyPrefixWith;rule.redirect = webRe;let routingRules = QCloudWebsiteRoutingRules.init();routingRules.routingRule = [rule];// Redirect rule configuration. Up to 100 RoutingRule values can be setconfig.rules = routingRules;req.websiteConfiguration = config;req.finishBlock = {(result,error) inif let result = result {// result contains response headers} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().putBucketWebsite(req);
GET Bucket website
) is used to query the static website configuration associated with a bucket.QCloudGetBucketWebsiteRequest *getReq = [QCloudGetBucketWebsiteRequest new];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket.getReq.bucket = @"examplebucket-1250000000";[getReq setFinishBlock:^(QCloudWebsiteConfiguration * result,NSError * error) {// Set redirect rules. Up to 100 RoutingRule values can be setQCloudWebsiteRoutingRules *rules =result.rules;// Index documentQCloudWebsiteIndexDocument *indexDocument = result.indexDocument;// Error documentQCloudWebisteErrorDocument *errorDocument = result.errorDocument;// Redirect all requestsQCloudWebsiteRedirectAllRequestsTo *redirectAllRequestsTo = result.redirectAllRequestsTo;}];[[QCloudCOSXMLService defaultCOSXML] GetBucketWebsite:getReq];
let req = QCloudGetBucketWebsiteRequest.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket.req.bucket = "examplebucket-1250000000";req.setFinish {(result,error) inif let result = result {let rules = result.rules} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().getBucketWebsite(req);
DELETE Bucket website
) is used to delete the static website configuration of a bucket.QCloudDeleteBucketWebsiteRequest *delReq = [QCloudDeleteBucketWebsiteRequest new];// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketdelReq.bucket = @"examplebucket-1250000000";[delReq setFinishBlock:^(id outputObject, NSError *error) {// outputObject contains all the HTTP response headersNSDictionary* info = (NSDictionary *) outputObject;}];[[QCloudCOSXMLService defaultCOSXML] DeleteBucketWebsite:delReq];
let delReq = QCloudDeleteBucketWebsiteRequest.init();// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket.delReq.bucket = "examplebucket-1250000000";delReq.finishBlock = {(result,error) inif let result = result {// result contains response headers} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().deleteBucketWebsite(delReq);
Apakah halaman ini membantu?