You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Best Practices
Accessing TOS using CN domain names
Copy page
Download PDF
Accessing TOS using CN domain names
To ensure greater availability, TOS allows you to access the same bucket using both the .cn and .com domain names. This enables you to quickly switch to the .cn domain if the .com domain is unavailable, thereby preventing service disruption.​
Regions and endpoints​
​
Region name​
Region ID​
Endpoint​
S3 endpoint​
China (Beijing)​
cn-beijing​
Private Network Access: tos-cn-beijing.ivolces.cn​
Public Network Access: tos-cn-beijing.volces.cn​
Private Network Access: tos-s3-cn-beijing.ivolces.cn​
Public Network Access: tos-s3-cn-beijing.volces.cn​
China (Guangzhou)​
cn-guangzhou​
Private Network Access: tos-cn-guangzhou.ivolces.cn​
Public Network Access: tos-cn-guangzhou.volces.cn​
Private Network Access: tos-s3-cn-guangzhou.ivolces.cn​
Public Network Access: tos-s3-cn-guangzhou.volces.cn​
China (Shanghai)​
cn-shanghai​
Private Network Access: tos-cn-shanghai.ivolces.cn​
Public Network Access: tos-cn-shanghai.volces.cn​
Private Network Access: tos-s3-cn-shanghai.ivolces.cn​
Public Network Access: tos-s3-cn-shanghai.volces.cn​
​
Switching to CN domain names for disaster recovery​
If your TOS access domain is blocked or your DNS is poisoned, hijacked, or your NS records are modified along the DNS resolution chain, rendering your .com domain unavailable, you can switch to the .cn domain to access TOS.​
The following Go example shows how to switch domains. We recommend embedding this logic in your application code ahead of time so that you can use the .cn domain when domain-level faults occur.​
​
package main​
​
import (​
"context"​
"fmt"​
"io/ioutil"​
"os"​
​
"github.com/volcengine/ve-tos-golang-sdk/v2/tos"​
)​
​
func checkErr(err error) {​
if err != nil {​
if serverErr, ok := err.(*tos.TosServerError); ok {​
fmt.Println("Error:", serverErr.Error())​
fmt.Println("Request ID:", serverErr.RequestID)​
fmt.Println("Response Status Code:", serverErr.StatusCode)​
fmt.Println("Response Header:", serverErr.Header)​
fmt.Println("Response Err Code:", serverErr.Code)​
fmt.Println("Response Err Msg:", serverErr.Message)​
} else if clientErr, ok := err.(*tos.TosClientError); ok {​
fmt.Println("Error:", clientErr.Error())​
fmt.Println("Client Cause Err:", clientErr.Cause.Error())​
} else {​
fmt.Println("Error:", err)​
}​
panic(err)​
}​
}​
​
func main() {​
var (​
accessKey = os.Getenv("TOS_ACCESS_KEY")​
secretKey = os.Getenv("TOS_SECRET_KEY")​
// The endpoint for the bucket. For example, the endpoint for a bucket in China (Beijing) is https://tos-cn-beijing.volces.com.​
endpoint = "https://tos-cn-beijing.volces.com"​
cnEndpoint = "https://tos-cn-beijing.volces.cn"​
region = "cn-beijing"​
// Enter the bucket name.​
bucketName = "*** Provide your bucket name ***"​
// Enter the object name.​
objectKey = "*** Provide your object key ***"​
)​
// Initialize the client.​
client, err := tos.NewClientV2(endpoint, tos.WithRegion(region), tos.WithCredentials(tos.NewStaticCredentials(accessKey, secretKey)))​
checkErr(err)​
​
cnClient, err := tos.NewClientV2(cnEndpoint, tos.WithRegion(region), tos.WithCredentials(tos.NewStaticCredentials(accessKey, secretKey)))​
checkErr(err)​
​
// Implement the useCN function yourself. In this scenario, the returned result should be true.​
if useCN() {​
client = cnClient​
}​
​
// Download the object.​
output, err := client.GetObjectV2(context.Background(), &tos.GetObjectV2Input{​
Bucket: bucketName,​
Key: objectKey,​
})​
checkErr(err)​
defer output.Content.Close()​
fmt.Println("Get object request id: ", output.RequestID)​
fmt.Println("Get object response status code: ", output.StatusCode)​
body, err := ioutil.ReadAll(output.Content)​
checkErr(err)​
fmt.Println("Get Object body: ", body)​
}​
​
​
Last updated: 2026.02.25 17:01:04