• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Node.js SDK)
  4. Bucket-Related APIs
  5. PUT Bucket website

PUT Bucket website

API Description

You can use this API to set website hosting for a bucket.

Method Definition

ObsClient.setBucketWebsiteConfiguration(parameter, callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

String

Mandatory

Bucket name

RedirectAllRequestsTo

Object

Optional

Redirection rule of all requests

  

HostName

String

Mandatory

Host name used for redirection

Protocol

String

Optional

Protocol used for redirection. Possible values are:

  • http (default)
  • https

ErrorDocument

Object

Optional

Error page settings

  

Key

String

Optional

Page to return to when a 4XX error occurs

IndexDocument

Object

Optional

Default page settings

  

Suffix

String

Mandatory

Suffix that is appended to a request initiated for a directory on the website endpoint. For example, if the suffix is index.html and you request for samplebucket/images/, the data that is returned will be the object with the key name images/index.html in the samplebucket bucket. This field cannot be left blank or contain a slash (/).

RoutingRules

Object

Optional

Redirection rule information

  

RoutingRule

Array

Optional

Redirection rule list

  

Condition

Object

Optional

Matching conditions of a redirection rule

  

HttpErrorCodeReturnedEquals

String

Optional

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

KeyPrefixEquals

String

Optional

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

Redirect

Object

Mandatory

Details about a redirection request

  

Protocol

String

Optional

Protocol used for redirection. Possible values are:

  • http
  • https

HostName

String

Optional

Host name used for redirection

ReplaceKeyPrefixWith

String

Optional

Object name prefix used in the redirection request

ReplaceKeyWith

String

Optional

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

HttpRedirectCode

String

Optional

HTTP status code in the response to the redirection request

NOTE:
  • ErrorDocumentIndexDocument, and RoutingRules must be used together and they cannot be used with RedirectAllRequestsTo.
  • When ErrorDocumentIndexDocument, and RoutingRules are used together, RoutingRules can be null.
  • You must set either these three fields or RedirectAllRequestsTo.

Returned Result (InterfaceResult)

Field

Type

Description

RequestId

String

Request ID returned by the OBS server

Sample Code

obsClient.setBucketWebsiteConfiguration({
       Bucket : 'bucketname',
//     RedirectAllRequestsTo : {HostName : 'www.example.com', Protocol : 'https'}
       IndexDocument:{Suffix:'index.html'},
       ErrorDocument:{Key:'error.html'},
       RoutingRules:{
              RoutingRule:[
               {Condition:{HttpErrorCodeReturnedEquals:'404'},Redirect:{Protocol:'http',ReplaceKeyWith:'NotFound.html'}},
                  {Condition:{HttpErrorCodeReturnedEquals:'404'},Redirect:{Protocol:'https',ReplaceKeyWith:'test.html'}}
              ]
       }
},(err, result) => {
       if(err){
              console.error('Error-->' + err);
       }else{
              if(result.CommonMsg.Status < 300){
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
              }else{
                     console.log('Code-->' + result.CommonMsg.Code);
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});