diff --git a/cos.go b/cos.go index a6596e8..f13a238 100644 --- a/cos.go +++ b/cos.go @@ -22,7 +22,7 @@ import ( const ( // Version current go sdk version - Version = "0.7.18" + Version = "0.7.19" userAgent = "cos-go-sdk-v5/" + Version contentTypeXML = "application/xml" defaultServiceBaseURL = "http://service.cos.myqcloud.com" diff --git a/costesting/ci_test.go b/costesting/ci_test.go index bc5c905..84823ea 100644 --- a/costesting/ci_test.go +++ b/costesting/ci_test.go @@ -907,6 +907,52 @@ func (s *CosTestSuite) TestAccelerate() { assert.Equal(s.T(), opt.Type, res.Type, "GetAccelerate Failed") } +func (s *CosTestSuite) TestMultiCopy() { + u := "http://" + kRepBucket + "-" + s.Appid + ".cos." + kRepRegion + ".myqcloud.com" + iu, _ := url.Parse(u) + ib := &cos.BaseURL{BucketURL: iu} + c := cos.NewClient(ib, &http.Client{ + Transport: &cos.AuthorizationTransport{ + SecretID: os.Getenv("COS_SECRETID"), + SecretKey: os.Getenv("COS_SECRETKEY"), + }, + }) + + opt := &cos.BucketPutOptions{ + XCosACL: "public-read", + } + + // Notice in intranet the bucket host sometimes has i/o timeout problem + r, err := c.Bucket.Put(context.Background(), opt) + if err != nil && r.StatusCode == 409 { + fmt.Println("BucketAlreadyOwnedByYou") + } else if err != nil { + assert.Nil(s.T(), err, "PutBucket Failed") + } + + source := "test/objectMove1" + time.Now().Format(time.RFC3339) + expected := "test" + f := strings.NewReader(expected) + + r, err = c.Object.Put(context.Background(), source, f, nil) + assert.Nil(s.T(), err, "PutObject Failed") + + time.Sleep(3 * time.Second) + // Copy file + soruceURL := fmt.Sprintf("%s/%s", iu.Host, source) + dest := "test/objectMove1" + time.Now().Format(time.RFC3339) + _, _, err = s.Client.Object.MultiCopy(context.Background(), dest, soruceURL, nil) + assert.Nil(s.T(), err, "MultiCopy Failed") + + // Check content + resp, err := s.Client.Object.Get(context.Background(), dest, nil) + assert.Nil(s.T(), err, "GetObject Failed") + bs, _ := ioutil.ReadAll(resp.Body) + resp.Body.Close() + result := string(bs) + assert.Equal(s.T(), expected, result, "MultiCopy Failed, wrong content") +} + // End of api test // All methods that begin with "Test" are run as tests within a diff --git a/object.go b/object.go index e9b07cb..3b2bddb 100644 --- a/object.go +++ b/object.go @@ -35,7 +35,9 @@ type ObjectGetOptions struct { XCosSSECustomerKey string `header:"x-cos-server-side-encryption-customer-key,omitempty" url:"-" xml:"-"` XCosSSECustomerKeyMD5 string `header:"x-cos-server-side-encryption-customer-key-MD5,omitempty" url:"-" xml:"-"` - XCosTrafficLimit int `header:"x-cos-traffic-limit,omitempty" url:"-" xml:"-"` + //兼容其他自定义头部 + XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"` + XCosTrafficLimit int `header:"x-cos-traffic-limit,omitempty" url:"-" xml:"-"` // 下载进度, ProgressCompleteEvent不能表示对应API调用成功,API是否调用成功的判断标准为返回err==nil Listener ProgressListener `header:"-" url:"-" xml:"-"` @@ -355,9 +357,10 @@ func (s *ObjectService) Delete(ctx context.Context, name string, opt ...*ObjectD type ObjectHeadOptions struct { IfModifiedSince string `url:"-" header:"If-Modified-Since,omitempty"` // SSE-C - XCosSSECustomerAglo string `header:"x-cos-server-side-encryption-customer-algorithm,omitempty" url:"-" xml:"-"` - XCosSSECustomerKey string `header:"x-cos-server-side-encryption-customer-key,omitempty" url:"-" xml:"-"` - XCosSSECustomerKeyMD5 string `header:"x-cos-server-side-encryption-customer-key-MD5,omitempty" url:"-" xml:"-"` + XCosSSECustomerAglo string `header:"x-cos-server-side-encryption-customer-algorithm,omitempty" url:"-" xml:"-"` + XCosSSECustomerKey string `header:"x-cos-server-side-encryption-customer-key,omitempty" url:"-" xml:"-"` + XCosSSECustomerKeyMD5 string `header:"x-cos-server-side-encryption-customer-key-MD5,omitempty" url:"-" xml:"-"` + XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"` } // Head Object请求可以取回对应Object的元数据,Head的权限与Get的权限一致