您可以将存储空间配置成静态网站托管模式。配置生效后,访问网站相当于访问存储空间,并且能够自动跳转至指定的索引页面和错误页面。

更多关于静态网站托管的介绍,请参见开发指南中的配置静态网站托管

设置静态网站托管

通过Bucket#website=来设置静态网站托管:

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  endpoint: 'endpoint',
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')

bucket = client.get_bucket('my-bucket')
bucket.website = BucketWebsite.new(index: 'index.html', error: 'error.html')

查看静态网站托管配置

通过Bucket#website来查看静态网站托管配置:

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  endpoint: 'endpoint',
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')

bucket = client.get_bucket('my-bucket')
web = bucket.website
puts web.to_s

删除静态网站托管配置

通过Bucket#website=来删除静态网站托管配置:

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  endpoint: 'endpoint',
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')

bucket = client.get_bucket('my-bucket')
bucket.website = BucketWebsite.new(enable: false)