API | 操作名 | 操作描述 |
设置存储桶 Referer | 设置存储桶 Referer 白名单或者黑名单 | |
查询存储桶 Referer | 查询存储桶 Referer 白名单或者黑名单 |
public void setBucketRefererConfiguration(String bucketName, BucketRefererConfiguration configuration) throws CosClientException, CosServiceException;public void setBucketRefererConfiguration(SetBucketRefererConfigurationRequest setBucketRefererConfigurationRequest) throws CosClientException, CosServiceException;
// 源存储桶名称,需包含 appidString bucketName = "examplebucket-1250000000";BucketRefererConfiguration configuration = new BucketRefererConfiguration();// 启用防盗链configuration.setStatus(BucketRefererConfiguration.DISABLED);// 设置防盗链类型为白名单//configuration.setRefererType(BucketRefererConfiguration.WHITELIST);// 设置防盗链类型为黑名单 (与白名单二选一)configuration.setRefererType(BucketRefererConfiguration.BLACKLIST);// 填写要设置的域名configuration.addDomain("test.com");configuration.addDomain("test.1.com");//(可选)设置是否允许空防盗链访问,缺省就是 DENYconfiguration.setEmptyReferConfiguration(BucketRefererConfiguration.DENY);// configuration.setEmptyReferConfiguration(BucketRefererConfiguration.ALLOW);cosClient.setBucketRefererConfiguration(bucketName, configuration);
参数名 | 参数描述 | 类型 |
bucketName | 存储桶的命名格式为 BucketName-APPID,详情请参见 命名规范 | String |
configuration | 存储桶 Referer 配置 | BucketRefererConfiguration |
参数名 | 参数描述 | 类型 | 必选 | 方法 |
Status | 是否开启防盗链,枚举值:Enabled、Disabled | String | 是 | setStatus |
RefererType | 防盗链类型,枚举值:Black-List、White-List | String | 是 | setRefererType |
Domain | 生效域名,支持带端口和 IP、支持通配符*, 支持多条 | String | 是 | addDomain |
EmptyReferConfiguration | 是否允许空 Refer 访问,枚举值: Allow、Deny | String | 否 | setEmptyReferConfiguration |
public BucketRefererConfiguration getBucketRefererConfiguration(String bucketName) throws CosClientException, CosServiceException
// 源存储桶名称,需包含 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);}
参数名 | 参数描述 | 类型 |
bucketName | 存储桶的命名格式为 BucketName-APPID,详情请参见 命名规范 | String |
本页内容是否解决了您的问题?