All Products
Search
Document Center

Object Storage Service:Map custom domain names

Last Updated:Oct 17, 2023

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 by 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(
  # Specify the custom domain name that you want to map to the bucket. 
  endpoint: 'http://example.com',
  # Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
  access_key_id: ENV['OSS_ACCESS_KEY_ID'],
  access_key_secret: ENV['OSS_ACCESS_KEY_SECRET'],
  cname: true
  )

# Specify the name of the bucket. Example: examplebucket. 
bucket = client.get_bucket('examplebucket')