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

Torch Object Storage

Copy page
Download PDF
Manage Bucket Configuration
Managing Custom Domain Names (Java SDK)
Copy page
Download PDF
Managing Custom Domain Names (Java SDK)
After you upload a file to TOS, you can access or download it using the file URL automatically generated by TOS. If you wish to use your own domain name to access files stored in TOS, you can associate your custom domain with the bucket. After association, you can use the corresponding domain name to access your files.​
Configure Custom Domain Name Rules​
You can obtain the custom domain configuration of a specified bucket through the putBucketCustomDomain interface of the TOS Java SDK.​
warning​
  • Each domain name can only be associated with one bucket.​
  • Each bucket can hold up to 20 bound domain names.​
Sample Code​
The following code demonstrates how to configure a custom domain name for a bucket.​
​
import com.volcengine.tos.TOSV2;​
import com.volcengine.tos.TOSV2ClientBuilder;​
import com.volcengine.tos.TosClientException;​
import com.volcengine.tos.TosServerException;​
import com.volcengine.tos.model.bucket.CustomDomainRule;​
import com.volcengine.tos.model.bucket.PutBucketCustomDomainInput;​
import com.volcengine.tos.model.bucket.PutBucketCustomDomainOutput;​
​
public class PutBucketCustomDomainExample {​
public static void main(String[] args) {​
String endpoint = "your endpoint";​
String region = "your region";​
String accessKey = System.getenv("TOS_ACCESS_KEY");​
String secretKey = System.getenv("TOS_SECRET_KEY"); ​
​
String bucketName = "bucket-example";​
String customDomain = "example.test.com";​
​
TOSV2 tos = new TOSV2ClientBuilder().build(region, endpoint, accessKey, secretKey);​
​
try{​
CustomDomainRule rule = new CustomDomainRule().setDomain(customDomain);​
PutBucketCustomDomainInput input = new PutBucketCustomDomainInput().setBucket(bucketName).setRule(rule);​
PutBucketCustomDomainOutput output = tos.putBucketCustomDomain(input);​
System.out.println("putBucketCustomDomain succeed");​
} catch (TosClientException e) {​
System.out.println("putBucketCustomDomain failed");​
System.out.println("Message: " + e.getMessage());​
if (e.getCause() != null) {​
e.getCause().printStackTrace();​
}​
} catch (TosServerException e) {​
System.out.println("putBucketCustomDomain failed");​
System.out.println("StatusCode: " + e.getStatusCode());​
System.out.println("Code: " + e.getCode());​
System.out.println("Message: " + e.getMessage());​
System.out.println("RequestID: " + e.getRequestID());​
} catch (Throwable t) {​
System.out.println("putBucketCustomDomain failed");​
System.out.println("unexpected exception, message: " + t.getMessage());​
}​
}​
}​
​
Enumerate Custom Domain Name Rules​
You can obtain the list of custom domain names configured for a specified bucket through the listBucketCustomDomain interface of the TOS Java SDK.​
warning​
To list the custom domain names of a bucket, you must be the bucket owner by default.​
Sample Code​
The following code demonstrates how to list the custom domain names of a bucket.​
​
import com.volcengine.tos.TOSV2;​
import com.volcengine.tos.TOSV2ClientBuilder;​
import com.volcengine.tos.TosClientException;​
import com.volcengine.tos.TosServerException;​
import com.volcengine.tos.model.bucket.CustomDomainRule;​
import com.volcengine.tos.model.bucket.ListBucketCustomDomainInput;​
import com.volcengine.tos.model.bucket.ListBucketCustomDomainOutput;​
​
public class GetBucketCustomDomainExample {​
public static void main(String[] args) {​
String endpoint = "your endpoint";​
String region = "your region";​
String accessKey = System.getenv("TOS_ACCESS_KEY");​
String secretKey = System.getenv("TOS_SECRET_KEY"); ​
​
String bucketName = "bucket-example";​
​
TOSV2 tos = new TOSV2ClientBuilder().build(region, endpoint, accessKey, secretKey);​
​
try{​
ListBucketCustomDomainInput input = new ListBucketCustomDomainInput().setBucket(bucketName);​
ListBucketCustomDomainOutput output = tos.listBucketCustomDomain(input);​
System.out.println("listBucketCustomDomain succeed");​
if (output.getRule() != null && output.getRule().size() > 0) {​
for(int i = 0; i < output.getRule().size(); i++) {​
CustomDomainRule rule = output.getRule().get(i);​
System.out.println("No." + i + " domain is " + rule.getDomain());​
}​
}​
} catch (TosClientException e) {​
System.out.println("listBucketCustomDomain failed");​
System.out.println("Message: " + e.getMessage());​
if (e.getCause() != null) {​
e.getCause().printStackTrace();​
}​
} catch (TosServerException e) {​
System.out.println("listBucketCustomDomain failed");​
System.out.println("StatusCode: " + e.getStatusCode());​
System.out.println("Code: " + e.getCode());​
System.out.println("Message: " + e.getMessage());​
System.out.println("RequestID: " + e.getRequestID());​
} catch (Throwable t) {​
System.out.println("listBucketCustomDomain failed");​
System.out.println("unexpected exception, message: " + t.getMessage());​
}​
}​
}​
​
Delete Custom Domain Name Rules​
You can delete the custom domain configured for a specified bucket by using the deleteBucketCustomDomain interface of the TOS Java SDK.​
warning​
To delete a bucket's custom domain name, you must, by default, be the bucket owner.​
Sample Code​
The following code demonstrates how to delete custom domain name rules for a bucket.​
​
import com.volcengine.tos.TOSV2;​
import com.volcengine.tos.TOSV2ClientBuilder;​
import com.volcengine.tos.TosClientException;​
import com.volcengine.tos.TosServerException;​
import com.volcengine.tos.model.bucket.DeleteBucketCustomDomainInput;​
import com.volcengine.tos.model.bucket.DeleteBucketCustomDomainOutput;​
​
public class DeleteBucketCustomDomainExample {​
public static void main(String[] args) {​
String endpoint = "your endpoint";​
String region = "your region";​
String accessKey = System.getenv("TOS_ACCESS_KEY");​
String secretKey = System.getenv("TOS_SECRET_KEY"); ​
String bucketName = "bucket-example";​
​
String customDomain = "example.test.com";​
​
TOSV2 tos = new TOSV2ClientBuilder().build(region, endpoint, accessKey, secretKey);​
​
try{​
DeleteBucketCustomDomainInput input = new DeleteBucketCustomDomainInput().setBucket(bucketName)​
.setDomain(customDomain);​
DeleteBucketCustomDomainOutput output = tos.deleteBucketCustomDomain(input);​
System.out.println("deleteBucketCustomDomain succeed, " + output);​
} catch (TosClientException e) {​
System.out.println("deleteBucketCustomDomain failed");​
System.out.println("Message: " + e.getMessage());​
if (e.getCause() != null) {​
e.getCause().printStackTrace();​
}​
} catch (TosServerException e) {​
System.out.println("deleteBucketCustomDomain failed");​
System.out.println("StatusCode: " + e.getStatusCode());​
System.out.println("Code: " + e.getCode());​
System.out.println("Message: " + e.getMessage());​
System.out.println("RequestID: " + e.getRequestID());​
} catch (Throwable t) {​
System.out.println("deleteBucketCustomDomain failed");​
System.out.println("unexpected exception, message: " + t.getMessage());​
}​
}​
}​
​
Related documentation​
For more information on custom domain configuration, see Custom Domain.​
Last updated: 2025.09.19 20:00:28