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 |
public void setBucketRefererConfiguration(String bucketName, BucketRefererConfiguration configuration) throws CosClientException, CosServiceException;public void setBucketRefererConfiguration(SetBucketRefererConfigurationRequest setBucketRefererConfigurationRequest) throws CosClientException, CosServiceException;
// Source bucket name, including appidString bucketName = "examplebucket-1250000000";BucketRefererConfiguration configuration = new BucketRefererConfiguration();// Enable hotlink protectionconfiguration.setStatus(BucketRefererConfiguration.DISABLED);// Set the hotlink protection type to allowlist//configuration.setRefererType(BucketRefererConfiguration.WHITELIST);// Set the hotlink protection type to blocklist (either allowlist or blocklist)configuration.setRefererType(BucketRefererConfiguration.BLACKLIST);// Enter the domain name to be setconfiguration.addDomain("test.com");configuration.addDomain("test.1.com");// (Optional) Set whether to allow access with an empty referer (default value: DENY)configuration.setEmptyReferConfiguration(BucketRefererConfiguration.DENY);// configuration.setEmptyReferConfiguration(BucketRefererConfiguration.ALLOW);cosClient.setBucketRefererConfiguration(bucketName, configuration);
Parameter | Description | Type |
bucketName | String | |
configuration | Referer configuration of a bucket | BucketRefererConfiguration |
Parameter | Description | Type | Required | Method |
Status | Whether to enable hotlink protection. Enumerated values: Enabled , Disabled | String | Yes | setStatus |
RefererType | Hotlink protection type. Enumerated values: Black-List , White-List | String | Yes | setRefererType |
Domain | Effective domain name. Supports one or multiple domain names with port numbers and IPs. The wildcard * is also supported. | String | Yes | addDomain |
EmptyReferConfiguration | Whether to allow access with an empty referer. Enumerated values: Allow , Deny | String | No | setEmptyReferConfiguration |
CosClientException
or CosServiceException
exception will be thrown. For more information, please see Troubleshooting.public BucketRefererConfiguration getBucketRefererConfiguration(String bucketName) throws CosClientException, CosServiceException
// Source bucket name, including appidString bucketName = "examplebucket-1250000000";BucketRefererConfiguration configuration = cosClient.getBucketRefererConfiguration(bucketName);if (configuration == null) {System.out.printf("bucket %s does not have referer configuration\\n", bucketName);return;}System.out.printf("status: %s\\n", configuration.getStatus());System.out.printf("referer type: %s\\n", configuration.getRefererType());System.out.printf("empty referer config: %s\\n", configuration.getEmptyReferConfiguration());for (String domain : configuration.getDomainList()) {System.out.printf("domain: %s\\n", domain);}
Parameter | Description | Type |
bucketName | String |
CosClientException
or CosServiceException
exception will be thrown. For more information, please see Troubleshooting.
Was this page helpful?