tencent cloud

All product documents
Cloud Object Storage
Hotlink Protection
Last updated: 2024-02-02 12:12:58
Hotlink Protection
Last updated: 2024-02-02 12:12:58

Overview

This document provides an overview of APIs and SDK code samples related to bucket referer allowlist or blocklist.
Note:
v5.5.0 or later is required.
API
Operation
Description
Setting bucket referer configuration
Sets a bucket referer allowlist or blocklist
Querying bucket referer configuration
Queries a bucket referer allowlist or blocklist

Setting Bucket Referer Configuration

Description

This API (PUT Bucket referer) is used to set a referer allowlist/blocklist for a bucket.

Method prototype

CosResult PutBucketReferer(const PutBucketRefererReq& request, PutBucketRefererResp* response);

Sample request

qcloud_cos::CosConfig config("./config.json");
qcloud_cos::CosAPI cos(config);
std::string bucket_name = "examplebucket-1250000000"; // Replaced with the bucket name

qcloud_cos::PutBucketRefererReq req(bucket_name);
qcloud_cos::PutBucketRefererResp resp;
// Construct the request as needed
req.SetStatus("Enabled");
req.SetRefererType("White-List");
req.AddDomain("test1.com");
req.AddDomain("test2.com");
qcloud_cos::CosResult result = cos.PutBucketReferer(req, &resp);
if (result.IsSucc()) {
// Request succeeded
} else {
// Request failed. You can call the CosResult member functions to output the error information, such as requestID.
}

Parameter description

Parameter
Description
Type
Required
req
Request of the PutBucketReferer operation
PutBucketRefererReq
Yes
resp
Response of the PutBucketReferer operation
PutBucketRefererResp
Yes

Response description

No

Querying Bucket Referer Configuration

Description

This API (GET Bucket referer) is used to query the referer allowlist/blocklist of a bucket.

Method prototype

CosResult GetBucketReferer(const GetBucketRefererReq& request, GetBucketRefererResp* response);

Sample request

qcloud_cos::CosConfig config("./config.json");
qcloud_cos::CosAPI cos(config);
std::string bucket_name = "examplebucket-1250000000"; // Replaced with the bucket name

qcloud_cos::GetBucketRefererReq req(bucket_name);
qcloud_cos::GetBucketRefererResp resp;
qcloud_cos::CosResult result = cos.GetBucketReferer(req, &resp);
if (result.IsSucc()) {
// Request succeeded. Obtain the referer configuration.
std::cout << "Status:" << resp.GetStatus() << std::endl;
std::cout << "RefererType:" << resp.GetRefererType() << std::endl;
for (auto& domain : resp.GetDomainList()) {
std::cout << "Domain:" << domain << std::endl;
}
std::cout << "EmptyReferConfiguration:" << resp.GetEmptyReferConf() << std::endl;
} else {
// Request failed. You can call the CosResult member functions to output the error information, such as requestID.
}

Parameter description

Parameter
Description
Type
Required
req
Request of the GetBucketReferer operation
GetBucketRefererReq
Yes
resp
Response of the GetBucketReferer operation
GetBucketRefererResp
Yes

Response description

No
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon