原图保护
更新时间:2026-08-04
PutBucketCopyrightProtection
本接口用来开启Bucket的原图保护功能,并指定resource字段,表示生效的资源范围。 对于开通原图保护的文件,不允许匿名下载访问该文件,或带自定义图片处理参数访问,只允许使用style样式访问或携带合法签名访问。
用户必须拥有FULL_CONTROL权限。
相关参数参见PutBucketCopyrightProtection接口。
C++
1void put_bucket_copyright_protection(Client &client) {
2 BucketCopyrightProtectionConfiguration configuration;
3 configuration.resources.push_back(g_bucket + "/images/*");
4 configuration.resources.push_back(g_bucket + "/original.jpg");
5 PutBucketCopyrightProtectionRequest request(g_bucket, configuration);
6 PutBucketCopyrightProtectionResponse response;
7 client.put_bucket_copyright_protection(request, &response);
8 print_common_response(response);
9}
GetCopyrightProtection
本接口用来获取某个Bucket的原图保护配置情况。
请求者拥有FULL_CONTROL权限才允许查看,否则返回403错误,错误码为AccessDenied。
相关参数参见GetCopyrightProtection接口。
C++
1void get_bucket_copyright_protection(Client &client) {
2 GetBucketCopyrightProtectionRequest request(g_bucket);
3 GetBucketCopyrightProtectionResponse response;
4 client.get_bucket_copyright_protection(request, &response);
5 print_common_response(response);
6 if (response.is_ok()) {
7 const std::vector<std::string> &resources = response.configuration().resources;
8 for (size_t i = 0; i < resources.size(); ++i) {
9 std::cout << "resource " << i << ": " << resources[i] << std::endl;
10 }
11 }
12}
DeleteCopyrightProtection
本接口用来关闭Bucket原图保护功能。
- 请求者只有拥有FULL_CONTROL权限才允许关闭原图保护功能,否则返回403错误,错误码为AccessDenied。
- 如果请求的Bucket没有开通原图保护功能,依然返回HTTP状态码204。
相关参数参见DeleteCopyrightProtection接口。
C++
1void delete_bucket_copyright_protection(Client &client) {
2 DeleteBucketCopyrightProtectionRequest request(g_bucket);
3 DeleteBucketCopyrightProtectionResponse response;
4 client.delete_bucket_copyright_protection(request, &response);
5 print_common_response(response);
6}
评价此篇文章
