package mainimport ("context""fmt""github.com/tencentyun/cos-go-sdk-v5""net/http""net/url""strings")func main() {// Replace examplebucket-1250000000 and COS_REGION with the actual informationu, _ := url.Parse("https://examplebucket-1250000000.cos.COS_REGION.myqcloud.com")b := &cos.BaseURL{BucketURL: u}client := cos.NewClient(b, &http.Client{Transport: &cos.AuthorizationTransport{SecretID: "SECRETID", // Replace it with the actual SecretId, which can be viewed and managed at https://console.tencentcloud.com/cam/capiSecretKey: "SECRETKEY", // Replace it with the actual SecretKey, which can be viewed and managed at https://console.tencentcloud.com/cam/capi},})// Disable CRC64 verification. CRC64 verification is enabled by default. You are strongly advised not to disable CRC64 verification.// client.Conf.EnableCRC = falsename := "exampleobject"// Upload the object with a stringf := strings.NewReader("test")// The SDK automatically verifies the CRC64 valueresp, err := client.Object.Put(context.Background(), name, f, nil)if err != nil {// ERROR}// Get the CRC64 value from the response headerfmt.Printf("CRC64: %v\\n", resp.Header.Get("x-cos-hash-crc64ecma"))}
Parameter | Description | Type |
Response | HTTP response | Struct |
Response.Header | HTTP response header | Struct |
Response.Body | HTTP response data | Struct |
Apakah halaman ini membantu?