您可以将存储空间配置成静态网站托管模式。配置生效后,访问网站相当于访问存储空间,并且能够自动跳转至指定的索引页面和错误页面。
设置静态网站托管
以下代码用于设置静态网站托管:
from src.ossConfig import ossConfig
import unicloud_oss.Oss as Oss access_key = 'youraccesskey' secret_key = 'yoursectetkey' endpoint_url = 'http://XXXXXXXXXXXXXXXXX.com' config = ossConfig(access_key,secret_key,endpoint_url) bucket_name = 'test1' #put_bucket_website website_configuration = { 'IndexDocument': {'Suffix': 'myindex.html'}, 'ErrorDocument': {'Key': 'myerror.html'} } if Oss.put_bucket_website(config, bucket_name, website_configuration): print("put bucket_website sucess!") else: print("put bucket_website failed!") |
查看静态网站托管配置
以下代码用于查看静态网站托管配置:
from src.ossConfig import ossConfig
import unicloud_oss.Oss as Oss access_key = 'youraccesskey' secret_key = 'yoursecretkey' endpoint_url = 'http://XXXXXXXXXXXXXXXXX.com' config = ossConfig(access_key,secret_key,endpoint_url) bucket_name = 'test1' #get_website_configuration get_website_configuration = Oss.get_bucket_website(config, bucket_name) if get_website_configuration is not None: print(get_website_configuration) else: print("Error OR This bucket is not set website!") |
删除静态网站托管配置
以下代码用于删除静态网站托管配置:
from src.ossConfig import ossConfig
import unicloud_oss.Oss as Oss access_key = 'youraccesskey' secret_key = 'yoursecretkey' endpoint_url = 'http://XXXXXXXXXXXXXXXXX.com' config = ossConfig(access_key,secret_key,endpoint_url) bucket_name = 'test1' #delete_bucket_website if Oss.delete_bucket_website(config, bucket_name): print("delete bucket_website sucess!") else: print("delete bucket_website failed!") |