After you upload objects to a bucket, Object Storage Service (OSS) automatically generates URLs for the uploaded objects. You can use these URLs to access the objects. If you want to access the objects using custom domain names, map the custom domain names to the buckets in which the objects are stored and add CNAME records for the custom domain names.
Prerequisites
A custom domain name is mapped to the bucket. For more information, see Map custom domain names.
Examples
The following code provides an example on how to initialize a custom domain name:
Important
Custom domain names cannot be used to call the list_buckets operation.
require 'aliyun/oss'
include Aliyun::OSS
client = Client.new(
# Use a custom domain name as the endpoint.
endpoint: 'http://example.com',
# Obtain access credentials from environment variables. Before you run this code example, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
access_key_id: ENV['OSS_ACCESS_KEY_ID'],
access_key_secret: ENV['OSS_ACCESS_KEY_SECRET'],
cname: true
)
# Specify the bucket name. For example, examplebucket.
bucket = client.get_bucket('examplebucket')