Skip to content

Commit 6f7db25

Browse files
authored
Merge pull request #101 from agin719/cos-v4-dev
add get object optional and test
2 parents d2273eb + 847dd57 commit 6f7db25

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

cos.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
const (
2424
// Version current go sdk version
25-
Version = "0.7.18"
25+
Version = "0.7.19"
2626
userAgent = "cos-go-sdk-v5/" + Version
2727
contentTypeXML = "application/xml"
2828
defaultServiceBaseURL = "http://service.cos.myqcloud.com"

costesting/ci_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,52 @@ func (s *CosTestSuite) TestAccelerate() {
907907
assert.Equal(s.T(), opt.Type, res.Type, "GetAccelerate Failed")
908908
}
909909

910+
func (s *CosTestSuite) TestMultiCopy() {
911+
u := "http://" + kRepBucket + "-" + s.Appid + ".cos." + kRepRegion + ".myqcloud.com"
912+
iu, _ := url.Parse(u)
913+
ib := &cos.BaseURL{BucketURL: iu}
914+
c := cos.NewClient(ib, &http.Client{
915+
Transport: &cos.AuthorizationTransport{
916+
SecretID: os.Getenv("COS_SECRETID"),
917+
SecretKey: os.Getenv("COS_SECRETKEY"),
918+
},
919+
})
920+
921+
opt := &cos.BucketPutOptions{
922+
XCosACL: "public-read",
923+
}
924+
925+
// Notice in intranet the bucket host sometimes has i/o timeout problem
926+
r, err := c.Bucket.Put(context.Background(), opt)
927+
if err != nil && r.StatusCode == 409 {
928+
fmt.Println("BucketAlreadyOwnedByYou")
929+
} else if err != nil {
930+
assert.Nil(s.T(), err, "PutBucket Failed")
931+
}
932+
933+
source := "test/objectMove1" + time.Now().Format(time.RFC3339)
934+
expected := "test"
935+
f := strings.NewReader(expected)
936+
937+
r, err = c.Object.Put(context.Background(), source, f, nil)
938+
assert.Nil(s.T(), err, "PutObject Failed")
939+
940+
time.Sleep(3 * time.Second)
941+
// Copy file
942+
soruceURL := fmt.Sprintf("%s/%s", iu.Host, source)
943+
dest := "test/objectMove1" + time.Now().Format(time.RFC3339)
944+
_, _, err = s.Client.Object.MultiCopy(context.Background(), dest, soruceURL, nil)
945+
assert.Nil(s.T(), err, "MultiCopy Failed")
946+
947+
// Check content
948+
resp, err := s.Client.Object.Get(context.Background(), dest, nil)
949+
assert.Nil(s.T(), err, "GetObject Failed")
950+
bs, _ := ioutil.ReadAll(resp.Body)
951+
resp.Body.Close()
952+
result := string(bs)
953+
assert.Equal(s.T(), expected, result, "MultiCopy Failed, wrong content")
954+
}
955+
910956
// End of api test
911957

912958
// All methods that begin with "Test" are run as tests within a

object.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ type ObjectGetOptions struct {
3535
XCosSSECustomerKey string `header:"x-cos-server-side-encryption-customer-key,omitempty" url:"-" xml:"-"`
3636
XCosSSECustomerKeyMD5 string `header:"x-cos-server-side-encryption-customer-key-MD5,omitempty" url:"-" xml:"-"`
3737

38-
XCosTrafficLimit int `header:"x-cos-traffic-limit,omitempty" url:"-" xml:"-"`
38+
//兼容其他自定义头部
39+
XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"`
40+
XCosTrafficLimit int `header:"x-cos-traffic-limit,omitempty" url:"-" xml:"-"`
3941

4042
// 下载进度, ProgressCompleteEvent不能表示对应API调用成功,API是否调用成功的判断标准为返回err==nil
4143
Listener ProgressListener `header:"-" url:"-" xml:"-"`
@@ -355,9 +357,10 @@ func (s *ObjectService) Delete(ctx context.Context, name string, opt ...*ObjectD
355357
type ObjectHeadOptions struct {
356358
IfModifiedSince string `url:"-" header:"If-Modified-Since,omitempty"`
357359
// SSE-C
358-
XCosSSECustomerAglo string `header:"x-cos-server-side-encryption-customer-algorithm,omitempty" url:"-" xml:"-"`
359-
XCosSSECustomerKey string `header:"x-cos-server-side-encryption-customer-key,omitempty" url:"-" xml:"-"`
360-
XCosSSECustomerKeyMD5 string `header:"x-cos-server-side-encryption-customer-key-MD5,omitempty" url:"-" xml:"-"`
360+
XCosSSECustomerAglo string `header:"x-cos-server-side-encryption-customer-algorithm,omitempty" url:"-" xml:"-"`
361+
XCosSSECustomerKey string `header:"x-cos-server-side-encryption-customer-key,omitempty" url:"-" xml:"-"`
362+
XCosSSECustomerKeyMD5 string `header:"x-cos-server-side-encryption-customer-key-MD5,omitempty" url:"-" xml:"-"`
363+
XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"`
361364
}
362365

363366
// Head Object请求可以取回对应Object的元数据,Head的权限与Get的权限一致

0 commit comments

Comments
 (0)