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 (C++ SDK)
Copy page
Download PDF
Managing Custom Domain Names (C++ SDK)
After you upload a file to TOS, you can access or download the file using the file URL automatically generated by TOS. If you wish to access files stored in TOS using your own domain name, you can bind your domain name to the storage bucket. Once binding is complete, files can be accessed using the corresponding domain name. The TOS C++ SDK supports binding custom domain names to storage buckets.​
Configure Custom Domain Name Rules​
warning​
  • A domain name can be bound to only one storage bucket.​
  • A storage bucket can be bound to up to 20 domain names.​
Sample Code​
The following code is used to configure custom domain name rules for the bucket examplebucket.​
​
#include "TosClientV2.h"​
using namespace VolcengineTos;​
​
int main(void){​
​
​
std::string region = "Your Region";​
std::string accessKey = std::getenv("TOS_ACCESS_KEY");​
std::string secretKey = std::getenv("TOS_SECRET_KEY");​
​
std::string bucketName = "examplebucket";​
​
std::string domain = "www.example.com";​
​
InitializeClient();​
​
TosClientV2 client(region, accessKey, secretKey);​
​
PutBucketCustomDomainInput input(bucketName);​
CustomDomainRule rule;​
​
rule.setDomain(domain);​
​
rule.setCertId("your cert id");​
​
rule.setCertStatus(CertStatusType::Bound);​
​
rule.setForbidden(true);​
​
rule.setForbiddenReason("your forbidden reason");​
input.setRules({rule});​
auto output = client.putBucketCustomDomain(input);​
if (!output.isSuccess()) {​
​
std::cout << "PutBucketCustomDomain failed." << output.error().String() << std::endl;​
​
CloseClient();​
return -1;​
}​
std::cout << "PutBucketCustomDomain success." << std::endl;​
​
​
CloseClient();​
return 0;​
}​
​
Enumerate Custom Domain Name Rules​
warning​
By default, you must be the bucket owner to list the custom domain name rules for a bucket.​
Sample Code​
The following code is used to enumerate the custom domain name rules for the bucket 'examplebucket'.​
​
#include "TosClientV2.h"​
using namespace VolcengineTos;​
​
int main(void){​
​
​
std::string region = "Your Region";​
std::string accessKey = std::getenv("TOS_ACCESS_KEY");​
std::string secretKey = std::getenv("TOS_SECRET_KEY");​
​
std::string bucketName = "examplebucket";​
​
​
InitializeClient();​
​
TosClientV2 client(region, accessKey, secretKey);​
ListBucketCustomDomainInput input(bucketName);​
​
auto output = client.listBucketCustomDomain(input);​
if (!output.isSuccess()) {​
​
std::cout << "ListBucketCustomDomain failed." << output.error().String() << std::endl;​
​
CloseClient();​
return -1;​
}​
std::cout << "ListBucketCustomDomain success." << std::endl;​
for (const auto& rule : output.result().getRules()) {​
std::cout << "domain:" << rule.getDomain() << std::endl;​
std::cout << "cname:" << rule.getCname() << std::endl;​
std::cout << "cert id:" << rule.getCertId() << std::endl;​
std::cout << "cert status:" << rule.getStringFormatCertStatus() << std::endl;​
std::cout << "is forbidden:" << rule.isForbidden() << std::endl;​
std::cout << "forbidden reason:" << rule.getForbiddenReason() << std::endl;​
}​
​
​
CloseClient();​
return 0;​
}​
​
Delete Custom Domain Name Rules​
warning​
To delete a bucket's custom domain name rule, you must, by default, be the bucket owner.​
Sample Code​
The following code is used to delete the custom domain name rules for the bucket examplebucket.​
​
#include "TosClientV2.h"​
using namespace VolcengineTos;​
​
int main(void){​
​
​
std::string region = "Your Region";​
std::string accessKey = std::getenv("TOS_ACCESS_KEY");​
std::string secretKey = std::getenv("TOS_SECRET_KEY");​
​
std::string bucketName = "examplebucket";​
​
std::string domain = "www.example.com";​
​
​
InitializeClient();​
​
TosClientV2 client(region, accessKey, secretKey);​
DeleteBucketCustomDomainInput input(bucketName,domain);​
auto output = client.deleteBucketCustomDomain(input);​
if (!output.isSuccess()) {​
​
std::cout << "DeleteBucketCustomDomain failed." << output.error().String() << std::endl;​
​
CloseClient();​
return -1;​
}​
std::cout << "DeleteBucketCustomDomain success." << std::endl;​
​
CloseClient();​
return 0;​
}​
​
Relevant Documentation​
For more information about custom domain configuration, see Custom Domain.​
Last updated: 2025.09.25 14:22:46