• Object Storage Service

  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Python SDK)
  4. Static Website Hosting
  5. Website File Hosting

Website File Hosting

You can perform the following to implement website file hosting:

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

Sample code:

# Import the module.
from com.obs.client.obs_client import ObsClient
# Create an instance of ObsClient.
obsClient = ObsClient(
    access_key_id='*** Provide your Access Key ***',    
    secret_access_key='*** Provide your Secret Key ***',    

from com.obs.models.put_object_header import PutObjectHeader
headers = PutObjectHeader()
# Set the MIME type for the object.
headers.contentType = 'text/html'

# Upload an object.
resp = obsClient.putFile('bucketname', 'test.html', 'localfile.html', headers=headers)
if resp.status < 300:    
    print('requestId:', resp.requestId)
    # Set the object ACL to public-read.
    resp2 = obsClient.setObjectAcl('bucketname', 'test.html', aclControl='public-read')
    if resp2.status < 300:    
        print('requestId:', resp2.requestId)
        print('errorCode:', resp2.errorCode)    
        print('errorMessage:', resp2.errorMessage)
    print('errorCode:', resp.errorCode)    
    print('errorMessage:', resp.errorMessage)

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