更新时间:2021-03-18 GMT+08:00
分享

设置桶的Website配置

功能说明

设置桶的Website配置。

方法定义

ObsClient.setBucketWebsite

请求参数

字段名

类型

约束

说明

Bucket

String

必选

桶名。

RequestDate

String

Date

可选

指定请求时间。

说明:

当为String类型时,必须符合ISO8601或RFC822规范。

RedirectAllRequestsTo

Object

可选

所有请求重定向规则。

  

HostName

String

必选

重定向请求时使用的站点名。

Protocol

String

可选

重定向请求时使用的协议,支持的值:

  • http(默认)
  • https

ErrorDocument

Object

可选

错误页面配置。

  

Key

String

可选

指定当4XX错误出现时返回的页面。

IndexDocument

Object

可选

默认页面配置。

  

Suffix

String

必选

该字段被追加在对文件夹的请求的末尾(例如:配置的是“index.html”,请求的是“samplebucket/images/”,返回的数据将是“samplebucket”桶内名为“images/index.html”的对象的内容)。该字段不能为空或者包含“/”字符。

RoutingRules

Array

可选

重定向规则列表。

  

Condition

Object

可选

重定向规则的匹配条件。

  

HttpErrorCodeReturnedEquals

String

可选

重定向规则生效需要匹配的HTTP错误码。

KeyPrefixEquals

String

可选

重定向规则生效需要匹配的对象名前缀。

Redirect

Object

必选

重定向请求时的具体信息。

  

Protocol

String

可选

重定向请求时使用的协议,支持的值:

  • http
  • https

HostName

String

可选

重定向请求时使用的站点名。

ReplaceKeyPrefixWith

String

可选

重定向请求时使用的对象名前缀。

ReplaceKeyWith

String

可选

重定向请求时使用的对象名。不可与ReplaceKeyPrefixWith同时存在。

HttpRedirectCode

String

可选

重定向请求时响应中的HTTP状态码。

  • ErrorDocument、IndexDocument和RoutingRules必须配套使用,且与RedirectAllRequestsTo互斥。当设置了这三个字段时,不能设置RedirectAllRequestsTo;反之,当设置了RedirectAllRequestsTo时,不能设置ErrorDocument、IndexDocument和RoutingRules。
  • 当ErrorDocument、IndexDocument和RoutingRules三个字段一起使用时,RoutingRules可为空。
  • ErrorDocument、IndexDocument、RoutingRules与RedirectAllRequestsTo不能全为空。

返回结果(InterfaceResult)

字段名

类型

说明

RequestId

String

OBS服务端返回的请求ID。

代码样例

obsClient.setBucketWebsite({
       Bucket : 'bucketname',
//     RedirectAllRequestsTo : {HostName : 'www.example.com', Protocol : 'https'}
       IndexDocument:{Suffix:'index.html'},
       ErrorDocument:{Key:'error.html'},
       RoutingRules:[
           {Condition:{HttpErrorCodeReturnedEquals:'404'},Redirect:{Protocol:'http',ReplaceKeyWith:'NotFound.html'}},
           {Condition:{HttpErrorCodeReturnedEquals:'404'},Redirect:{Protocol:'https',ReplaceKeyWith:'test.html'}}
       ]
},function (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);
              }
       }
});
分享:

    相关文档

    相关产品