Pārlūkot izejas kodu

add sample for put object with cmkid

hangzws 6 gadi atpakaļ
vecāks
revīzija
4689ba2c29
2 mainītis faili ar 7 papildinājumiem un 1 dzēšanām
  1. 1 0
      sample/config.go
  2. 6 1
      sample/put_object.go

+ 1 - 0
sample/config.go

@@ -6,6 +6,7 @@ const (
 	accessID   string = "<AccessKeyId>"
 	accessKey  string = "<AccessKeySecret>"
 	bucketName string = "<my-bucket>"
+	kmsID      string = "<KmsID>"
 
 	// The cname endpoint
 	// These information are required to run sample/cname_sample

+ 6 - 1
sample/put_object.go

@@ -60,6 +60,11 @@ func PutObjectSample() {
 		HandleError(err)
 	}
 
+	err = bucket.PutObject(objectKey, strings.NewReader(val), oss.ServerSideEncryption("KMS"), oss.ServerSideEncryptionKeyID(kmsID))
+	if err != nil {
+		HandleError(err)
+	}
+
 	props, err := bucket.GetObjectDetailedMeta(objectKey)
 	if err != nil {
 		HandleError(err)
@@ -85,7 +90,7 @@ func PutObjectSample() {
 		HandleError(err)
 	}
 
-	// Specify the local file path for checkpoint files. 
+	// Specify the local file path for checkpoint files.
 	// the 2nd parameter of Checkpoint can specify the file path, when the file path is empty, it will upload the directory.
 	err = bucket.UploadFile(objectKey, localFile, 100*1024, oss.Checkpoint(true, localFile+".cp"))
 	if err != nil {