Feature Overview
This document provides an overview of APIs and SDK code samples related to bucket copying.
API | Operation | Description |
Setting Cross-Bucket Replication | Sets a cross-bucket replication rule for a versioning-enabled bucket | |
Querying a bucket replication rule | Queries the cross-bucket replication rule of a bucket | |
Deleting a bucket replication rule | Deletes a cross-bucket replication rule of a bucket |
Setting Cross-Bucket Replication
Note
This API (PUT Bucket replication) is used to set the cross-bucket replication rule for a bucket.
Method prototype
func (s *BucketService) PutBucketReplication(ctx context.Context, opt *PutBucketReplicationOptions) (*Response, error)
Sample Request
package mainimport ("context""github.com/tencentyun/cos-go-sdk-v5""net/http""net/url""os")func main() {// Bucket name, composed of bucketname-appid, appid is required. The bucket name can be viewed in the COS console: https://console.cloud.tencent.com/cos5/bucket// Replace with the user's region. The bucket region can be viewed in the COS console "Bucket Overview" at https://console.cloud.tencent.com/. For more information about regions, visit https://cloud.tencent.com/document/product/436/6224.u, _ := url.Parse("https://examplebucket-12500000000.cos.ap-guangzhou.myqcloud.com")b := &cos.BaseURL{BucketURL: u}client := cos.NewClient(b, &http.Client{Transport: &cos.AuthorizationTransport{// Get the key from environment variables// Environment variable SECRETID represents the user's SecretId. To view the key, log in to the Access Management Console at https://console.cloud.tencent.com/cam/capi.SecretID: os.Getenv("SECRETID"), // User's SecretId, it is recommended to use a sub-account key, following the principle of least privilege to reduce usage risks. For obtaining a sub-account key, please refer to https://cloud.tencent.com/document/product/598/37140// The environment variable SECRETKEY represents the user's SecretKey. To view the key, log in to the CAM console at https://console.cloud.tencent.com/cam/capi.SecretKey: os.Getenv("SECRETKEY"), // User's SecretKey, it is recommended to use a sub-account key, following the principle of least privilege to reduce usage risks. For obtaining a sub-account key, please refer to https://cloud.tencent.com/document/product/598/37140},})opt := &cos.PutBucketReplicationOptions{// qcs::cam::uin/[UIN]:uin/[Subaccount]Role: "qcs::cam::uin/100000000001:uin/100000000001",Rule: []cos.BucketReplicationRule{{ID: "1",// Enabled or DisabledStatus: "Enabled",Destination: &cos.ReplicationDestination{// qcs::cos:[Region]::[Bucketname-Appid]Bucket: "qcs::cos:ap-beijing::destinationbucket-1250000000",},},},}_, err := client.Bucket.PutBucketReplication(context.Background(), opt)if err != nil {panic(err)}}
Description
type PutBucketReplicationOptions struct {Role stringRule []BucketReplicationRule}type BucketReplicationRule struct {ID stringStatus stringPrefix stringDestination *ReplicationDestination}type ReplicationDestination struct {Bucket stringStorageClass string}
Parameter name | Description | Local Disk Types |
PutBucketReplicationOptions | Cross-bucket replication rules | struct |
Role | Initiator Identity Identifier: qcs::cam::uin/<OwnerUin>:uin/<SubUin> | string |
Rule | Specific configuration. You can set a maximum of 1,000 rules, which should apply to the same destination bucket | struct |
ID | Name of a specific rule | string |
Status | Rule status identifier. Enumerated values: Enabled, Disabled | string |
Prefix | Prefix matching policy. Policies cannot overlap; otherwise, an error will be returned. To match the root directory, leave this parameter empty. | string |
Destination | Destination bucket information | struct |
Bucket | Resource identifier, formatted as qcs::cos:[region]::[BucketName-APPID] | string |
StorageClass | Storage class, enumerated values: STANDARD, STANDARD_IA. For more types, please refer to the API overview above. Default value: original storage type. | string |
Querying a bucket replication rule
Note
This API (GET Bucket replication) is used to query the cross-bucket replication rule of a bucket.
Method prototype
func (s *BucketService) GetBucketReplication(ctx context.Context) (*GetBucketReplicationResult, *Response, error)
Sample Request
package mainimport ("context""github.com/tencentyun/cos-go-sdk-v5""net/http""net/url""os")func main() {// Bucket name, composed of bucketname-appid, appid is required. The bucket name can be viewed in the COS console: https://console.cloud.tencent.com/cos5/bucket// Replace with the user's region. The bucket region can be viewed in the COS console "Bucket Overview" at https://console.cloud.tencent.com/. For more information about regions, visit https://cloud.tencent.com/document/product/436/6224.u, _ := url.Parse("https://examplebucket-12500000000.cos.ap-guangzhou.myqcloud.com")b := &cos.BaseURL{BucketURL: u}client := cos.NewClient(b, &http.Client{Transport: &cos.AuthorizationTransport{// Get the key from environment variables// Environment variable SECRETID represents the user's SecretId. To view the key, log in to the Access Management Console at https://console.cloud.tencent.com/cam/capi.SecretID: os.Getenv("SECRETID"), // User's SecretId, it is recommended to use a sub-account key, following the principle of least privilege to reduce usage risks. For obtaining a sub-account key, please refer to https://cloud.tencent.com/document/product/598/37140// The environment variable SECRETKEY represents the user's SecretKey. To view the key, log in to the CAM console at https://console.cloud.tencent.com/cam/capi.SecretKey: os.Getenv("SECRETKEY"), // User's SecretKey, it is recommended to use a sub-account key, following the principle of least privilege to reduce usage risks. For obtaining a sub-account key, please refer to https://cloud.tencent.com/document/product/598/37140},})_, _, err := client.Bucket.GetBucketReplication(context.Background())if err != nil {panic(err)}}
Response description
type GetBucketReplicationResult struct {Role stringRule []BucketReplicationRule}type BucketReplicationRule struct {ID stringStatus stringPrefix stringDestination *ReplicationDestination}type ReplicationDestination struct {Bucket stringStorageClass string}
Parameter name | Description | Local Disk Types |
GetBucketReplicationResult | Cross-bucket replication rules | struct |
Role | Initiator Identity Identifier: qcs::cam::uin/<OwnerUin>:uin/<SubUin> | string |
Rule | Specific configuration. You can set a maximum of 1,000 rules, which should apply to the same destination bucket | struct |
ID | Name of a specific rule | string |
Status | Rule status identifier. Enumerated values: Enabled, Disabled | string |
Prefix | Prefix matching policy. Policies cannot overlap; otherwise, an error will be returned. To match the root directory, leave this parameter empty. | string |
Destination | Destination bucket information | struct |
Bucket | Resource identifier, formatted as qcs::cos:[region]::[BucketName-APPID] | string |
StorageClass | Storage class, enumerated values: STANDARD, STANDARD_IA. For more types, please refer to the API overview above. Default value: original storage type. | string |
Deleting a bucket replication rule
Note
This API (DELETE Bucket replication) is used to delete a cross-bucket replication rule from a bucket.
Method prototype
func (s *BucketService) DeleteBucketReplication(ctx context.Context) (*Response, error)
Sample Request
package mainimport ("context""github.com/tencentyun/cos-go-sdk-v5""net/http""net/url""os")func main() {// Bucket name, composed of bucketname-appid, appid is required. The bucket name can be viewed in the COS console: https://console.cloud.tencent.com/cos5/bucket// Replace with the user's region. The bucket region can be viewed in the COS console "Bucket Overview" at https://console.cloud.tencent.com/. For more information about regions, visit https://cloud.tencent.com/document/product/436/6224.u, _ := url.Parse("https://examplebucket-12500000000.cos.ap-guangzhou.myqcloud.com")b := &cos.BaseURL{BucketURL: u}client := cos.NewClient(b, &http.Client{Transport: &cos.AuthorizationTransport{// Get the key from environment variables// Environment variable SECRETID represents the user's SecretId. To view the key, log in to the Access Management Console at https://console.cloud.tencent.com/cam/capi.SecretID: os.Getenv("SECRETID"), // User's SecretId, it is recommended to use a sub-account key, following the principle of least privilege to reduce usage risks. For obtaining a sub-account key, please refer to https://cloud.tencent.com/document/product/598/37140// The environment variable SECRETKEY represents the user's SecretKey. To view the key, log in to the CAM console at https://console.cloud.tencent.com/cam/capi.SecretKey: os.Getenv("SECRETKEY"), // User's SecretKey, it is recommended to use a sub-account key, following the principle of least privilege to reduce usage risks. For obtaining a sub-account key, please refer to https://cloud.tencent.com/document/product/598/37140},})_, err := client.Bucket.DeleteBucketReplication(context.Background())if err != nil {panic(err)}}