Static Website Hosting

API Description

You can use this API to upload the files of the static website to your bucket in OBS as objects and configure the public-read permission on the files, and then configure the static website hosting mode for your bucket to host your static websites in OBS. After this, when third-party users access your websites, they actually access the objects in your bucket in OBS. When using static website hosting, you can configure request redirection to redirect specific or all requests.

For more information, see Static Website Hosting.

Website File Hosting

  1. Upload the website files to your bucket in OBS as objects and set the MIME type for the objects.
  2. Set the ACL of the object to public-read.
  3. Access the object using a browser.

Sample code is as follows:

// Import the dependency package.
import (
       "fmt"
       "obs"
)

var ak = "*** Provide your Access Key ***"
var sk = "*** Provide your Secret Key ***"
var endpoint = "https://your-endpoint"

// Create an ObsClient struct.
var obsClient, _ = obs.New(ak, sk, endpoint)

func main() {
       input := &obs.PutFileInput{}
       input.Bucket = "bucketname"
       input.Key = "test.html"
       input.SourceFile = "localfile.html"
       // Set the MIME type for the object.
       input.ContentType = "text/html"
       // Set the object ACL to public-read.
       input.ACL = obs.AclPublicRead
       // Upload an object.
       output, err := obsClient.PutFile(input)
       if err == nil {
              fmt.Printf("RequestId:%s\n", output.RequestId)
       } else if obsError, ok := err.(obs.ObsError); ok {
              fmt.Printf("Code:%s\n", obsError.Code)
              fmt.Printf("Message:%s\n", obsError.Message)
       }
}

You can use http://bucketname.your-endpoint/test.html in a browser to access files hosted using the sample code.