API | 操作名 | 操作描述 |
设置跨域配置 | 设置存储桶的跨域名访问权限 | |
查询跨域配置 | 查询存储桶的跨域名访问配置信息 | |
删除跨域配置 | 删除存储桶的跨域名访问配置信息 |
public void setBucketCrossOriginConfiguration(String bucketName, BucketCrossOriginConfiguration bucketCrossOriginConfiguration);
// bucket的命名格式为 BucketName-APPID ,此处填写的存储桶名称必须为此格式String bucketName = "examplebucket-1250000000";BucketCrossOriginConfiguration bucketCORS = new BucketCrossOriginConfiguration();List<CORSRule> corsRules = new ArrayList<CORSRule>();CORSRule corsRule = new CORSRule();// 规则名称corsRule.setId("set-bucket-cors-test");// 允许的 HTTP 方法corsRule.setAllowedMethods(CORSRule.AllowedMethods.PUT, CORSRule.AllowedMethods.GET, CORSRule.AllowedMethods.HEAD);corsRule.setAllowedHeaders("x-cos-grant-full-control");corsRule.setAllowedOrigins("http://mail.qq.com", "http://www.qq.com", "http://video.qq.com");corsRule.setExposedHeaders("x-cos-request-id");corsRule.setMaxAgeSeconds(60);corsRules.add(corsRule);bucketCORS.setRules(corsRules);cosClient.setBucketCrossOriginConfiguration(bucketName, bucketCORS);
参数名称 | 描述 | 类型 |
bucketName | 存储桶的命名格式为 BucketName-APPID,详情请参见 命名规范 | String |
bucketCrossOriginConfiguration | 设置的存储桶跨域策略 | BucketCrossOriginConfiguration |
public BucketCrossOriginConfiguration getBucketCrossOriginConfiguration(String bucketName)throws CosClientException, CosServiceException;
// bucket的命名格式为 BucketName-APPID ,此处填写的存储桶名称必须为此格式String bucketName = "examplebucket-1250000000";BucketCrossOriginConfiguration corsGet = cosClient.getBucketCrossOriginConfiguration(bucketName);List<CORSRule> corsRules = corsGet.getRules();for (CORSRule rule : corsRules) {List<CORSRule.AllowedMethods> allowedMethods = rule.getAllowedMethods();List<String> allowedHeaders = rule.getAllowedHeaders();List<String> allowedOrigins = rule.getAllowedOrigins();List<String> exposedHeaders = rule.getExposedHeaders();int maxAgeSeconds = rule.getMaxAgeSeconds();}
参数名称 | 描述 | 类型 |
bucketName | 存储桶的命名格式为 BucketName-APPID,详情请参见 命名规范 | String |
public void deleteBucketCrossOriginConfiguration(String bucketName)throws CosClientException, CosServiceException;
//存储桶的命名格式为 BucketName-APPIDString bucketName = "examplebucket-1250000000";cosClient.deleteBucketCrossOriginConfiguration(bucketName);
参数名称 | 描述 | 类型 |
bucketName | 存储桶的命名格式为 BucketName-APPID,详情请参见 命名规范 | String |
本页内容是否解决了您的问题?