XCosServerSideEncryption
member of ObjectPutHeaderOptions
.// Download the object. You need to provide the key to download the object. // Download the object. You need to provide the key to download the object. package mainimport ("context""errors""io/ioutil""net/http""net/url""os""strings""github.com/tencentyun/cos-go-sdk-v5""github.com/tencentyun/cos-go-sdk-v5/debug")func main(){// Replace it with your <Bucketname-APPID>u, _ := url.Parse("https://<Bucketname-APPID>.cos.ap-guangzhou.myqcloud.com")b := &cos.BaseURL{BucketURL: u}c := cos.NewClient(b, &http.Client{Transport: &cos.AuthorizationTransport{SecretID: os.Getenv("SECRETID"), // User `SecretId`. We recommend that you use a sub-account key and follow the principle of least privilege to reduce risks. For information about how to obtain a sub-account key, visit https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1.SecretKey: os.Getenv("SECRETKEY"), // User `SecretKey`. We recommend that you use a sub-account key and follow the principle of least privilege to reduce risks. For information about how to obtain a sub-account key, visit https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1.Transport: &debug.DebugRequestTransport{RequestHeader: true,// Notice when put a large file and set need the request body, might happend out of memory error.RequestBody: false,ResponseHeader: true,ResponseBody: true,},},})opt := &cos.ObjectPutOptions{ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{ContentType: "text/html",XCosServerSideEncryption: "AES256",},ACLHeaderOptions: &cos.ACLHeaderOptions{},}name := "PutFromGoWithSSE-COS"content := "Put Object From Go With SSE-COS"f := strings.NewReader(content)_, err := c.Object.Put(context.Background(), name, f, opt)if err != nil{panic(err)}// Download an objectgetopt := &cos.ObjectGetOptions{}var resp *cos.Responseresp, err = c.Object.Get(context.Background(), name, getopt)if err != nil{panic(err)}// VerifybodyBytes, _ := ioutil.ReadAll(resp.Body)bodyContent := string(bodyBytes)if bodyContent != content {panic(errors.New("Content inconsistency"))}}
XCosSSECustomer*
member of ObjectPutHeaderOptions
.package mainimport ("context""net/url""os""strings""errors""io/ioutil""net/http""github.com/tencentyun/cos-go-sdk-v5""github.com/tencentyun/cos-go-sdk-v5/debug")func main(){// Replace it with your <Bucketname-APPID>u, _ := url.Parse("https://<Bucketname-APPID>.cos.ap-guangzhou.myqcloud.com")b := &cos.BaseURL{BucketURL: u}c := cos.NewClient(b, &http.Client{Transport: &cos.AuthorizationTransport{SecretID: os.Getenv("SECRETID"), // User `SecretId`. We recommend that you use a sub-account key and follow the principle of least privilege to reduce risks. For information about how to obtain a sub-account key, visit https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1.SecretKey: os.Getenv("SECRETKEY"), // User `SecretKey`. We recommend you use a sub-account key and follow the principle of least privilege to reduce risks. For information about how to obtain a sub-account key, visit https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1.Transport: &debug.DebugRequestTransport{RequestHeader: true,// Notice when put a large file and set need the request body, might happend out of memory error.RequestBody: false,ResponseHeader: true,ResponseBody: true,},},})opt := &cos.ObjectPutOptions{ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{ContentType: "text/html",XCosSSECustomerAglo: "AES256",XCosSSECustomerKey: "MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY=",XCosSSECustomerKeyMD5: "U5L61r7jcwdNvT7frmUG8g==",},ACLHeaderOptions: &cos.ACLHeaderOptions{},}name := "PutFromGoWithSSE-C"content := "Put Object From Go With SSE-C"f := strings.NewReader(content)_, err := c.Object.Put(context.Background(), name, f, opt)if err != nil{panic(err)}Download the object. You need to provide the key to download the object.getopt := &cos.ObjectGetOptions{XCosSSECustomerAglo: "AES256",XCosSSECustomerKey: "MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY=",XCosSSECustomerKeyMD5: "U5L61r7jcwdNvT7frmUG8g==",}var resp *cos.Responseresp, err = c.Object.Get(context.Background(), name, getopt)if err != nil{panic(err)}// VerifybodyBytes, _ := ioutil.ReadAll(resp.Body)bodyContent := string(bodyBytes)if bodyContent != content {panic(errors.New("Content inconsistency"))}}
Apakah halaman ini membantu?