Updated on 2022-02-10 GMT+08:00

GET Bucket website

API Description

You can use this API to obtain the website hosting settings of a bucket.

Method Definition

ObsClient.getBucketWebsite

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

String

Mandatory

Bucket name

RequestDate

String

or

Date

Optional

Request time

NOTE:

When the parameter type is String, the value must comply with the ISO8601 or RFC822 standards.

Returned Result (InterfaceResult)

Field

Type

Description

RequestId

String

Request ID returned by the OBS server

RedirectAllRequestsTo

Object

Redirection rule of all requests

  

HostName

String

Host name used for redirection

Protocol

String

Host name used for redirection

ErrorDocument

Object

Error page settings

  

Key

String

Page that is returned when a 4XX error occurs

IndexDocument

Object

Default page settings

  

Suffix

String

Suffix that is appended to a request initiated for a folder. For example, if the suffix is index.html and you request for samplebucket/images/, the returned data will be the object named images/index.html in the samplebucket bucket. The suffix can neither be null nor contain slashes (/).

RoutingRules

Array

Redirection rule list

  

Condition

Object

Matching condition of a redirection rule

  

HttpErrorCodeReturnedEquals

String

HTTP error code to be matched when a redirection rule takes effect

KeyPrefixEquals

String

Object name prefix to be matched when a redirection rule takes effect

Redirect

Object

Details about a redirection request

  

Protocol

String

Protocol used for redirection

HostName

String

Host name used for redirection

ReplaceKeyPrefixWith

String

Object name prefix used in the redirection request

ReplaceKeyWith

String

Object name used in the redirection request. This parameter cannot be used together with ReplaceKeyPrefixWith.

HttpRedirectCode

String

HTTP status code in the response to the redirection request

Sample Code

obsClient.getBucketWebsite({
       Bucket : 'bucketname'
},function (err, result) {
       if(err){
              console.error('Error-->' + err);
       }else{
              if(result.CommonMsg.Status < 300){
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
                     console.log('RedirectAllRequestsTo:');
                     console.log('HostName-->' + result.InterfaceResult.RedirectAllRequestsTo['HostName']);
                     console.log('Protocol-->' + result.InterfaceResult.RedirectAllRequestsTo['Protocol']);
                     console.log('IndexDocument[Suffix]-->' + result.InterfaceResult.IndexDocument['Suffix']);
                     console.log('ErrorDocument[Key]-->' + result.InterfaceResult.ErrorDocument['Key']);
                     console.log('RoutingRules:');
                     for(var i=0;i<result.InterfaceResult.RoutingRules.length;i++){
                           console.log('RoutingRule[' + i + ']:');
                           var RoutingRule = result.InterfaceResult.RoutingRules[i];
                           console.log('Condition[HttpErrorCodeReturnedEquals]-->' + RoutingRule['Condition']['HttpErrorCodeReturnedEquals']);
                           console.log('Condition[KeyPrefixEquals]-->' + RoutingRule['Condition']['KeyPrefixEquals']);
                           console.log('Redirect[HostName]-->' + RoutingRule['Redirect']['HostName']);
                           console.log('Redirect[HttpRedirectCode]-->' + RoutingRule['Redirect']['HttpRedirectCode']);
                           console.log('Redirect[Protocol]-->' + RoutingRule['Redirect']['Protocol']);
                           console.log('Redirect[ReplaceKeyPrefixWith]-->' + RoutingRule['Redirect']['ReplaceKeyPrefixWith']);
                           console.log('Redirect[ReplaceKeyWith]-->' + RoutingRule['Redirect']['ReplaceKeyWith']);
                     }
              }else{
                     console.log('Code-->' + result.CommonMsg.Code);
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});