PUT Bucket website
API Description
You can use this API to set website hosting for a bucket.
Method Definition
ObsClient.setBucketWebsite
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:
|
||
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 |
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:
|
||
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 |
- ErrorDocument, IndexDocument, and RoutingRules must be used together and they cannot be used with RedirectAllRequestsTo.
- When ErrorDocument, IndexDocument, 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.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'}} ] },(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); } } });
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot