6 Commits

Author SHA1 Message Date
agin719
6bc7b5256c Merge pull request #89 from agin719/common-dev
fix ci_test
2020-11-25 07:00:42 -06:00
agin719
95b127211f Merge pull request #92 from agin719/tencentyun
update version
2020-11-25 06:58:49 -06:00
jojoliang
e4b5ad8337 update version 2020-11-25 20:57:37 +08:00
agin719
1942f2303e Merge pull request #91 from agin719/tencentyun
update presignedurl && copy
2020-11-25 06:56:27 -06:00
jojoliang
9a672cde0b update presignedurl && copy 2020-11-25 20:50:47 +08:00
jojoliang
d18e8cfac2 fix ci_test 2020-10-27 19:52:55 +08:00
4 changed files with 36 additions and 18 deletions

2
cos.go
View File

@@ -22,7 +22,7 @@ import (
const ( const (
// Version current go sdk version // Version current go sdk version
Version = "0.7.11" Version = "0.7.12"
userAgent = "cos-go-sdk-v5/" + Version userAgent = "cos-go-sdk-v5/" + Version
contentTypeXML = "application/xml" contentTypeXML = "application/xml"
defaultServiceBaseURL = "http://service.cos.myqcloud.com" defaultServiceBaseURL = "http://service.cos.myqcloud.com"

View File

@@ -56,7 +56,7 @@ const (
kBucket = "cosgosdktest-1259654469" kBucket = "cosgosdktest-1259654469"
kRegion = "ap-guangzhou" kRegion = "ap-guangzhou"
// 跨区域复制需要的目标存储桶地域不能与kBucket存储桶相同 // 跨区域复制需要的目标存储桶地域不能与kBucket存储桶相同, 目的存储桶需要开启多版本
kRepBucket = "cosgosdkreptest" kRepBucket = "cosgosdkreptest"
kRepRegion = "ap-chengdu" kRepRegion = "ap-chengdu"
@@ -85,9 +85,9 @@ func (s *CosTestSuite) SetupSuite() {
s.Region = p[2] s.Region = p[2]
// Bucket name // Bucket name
pp := strings.Split(p[0], "-") pi := strings.LastIndex(p[0], "-")
s.Bucket = pp[0] s.Bucket = p[0][:pi]
s.Appid = pp[1] s.Appid = p[0][pi+1:]
ib := &cos.BaseURL{BucketURL: bucketurl, BatchURL: batchurl} ib := &cos.BaseURL{BucketURL: bucketurl, BatchURL: batchurl}
s.Client = cos.NewClient(ib, &http.Client{ s.Client = cos.NewClient(ib, &http.Client{

View File

@@ -45,7 +45,7 @@ func cloneRequest(r *http.Request) *http.Request {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
// //
// http://www.ecma-international.org/ecma-262/6.0/#sec-uri-syntax-and-semantics // http://www.ecma-international.org/ecma-262/6.0/#sec-uri-syntax-and-semantics
func encodeURIComponent(s string) string { func encodeURIComponent(s string, excluded ...[]byte) string {
var b bytes.Buffer var b bytes.Buffer
written := 0 written := 0
@@ -71,6 +71,18 @@ func encodeURIComponent(s string) string {
continue continue
} }
if len(excluded) > 0 {
conti := false
for _, ch := range excluded[0] {
if ch == c {
conti = true
break
}
}
if conti {
continue
}
}
} }
b.WriteString(s[written:i]) b.WriteString(s[written:i])

View File

@@ -115,12 +115,12 @@ func (s *ObjectService) GetPresignedURL(ctx context.Context, httpMethod, name, a
authTime = NewAuthTime(expired) authTime = NewAuthTime(expired)
} }
authorization := newAuthorization(ak, sk, req, authTime) authorization := newAuthorization(ak, sk, req, authTime)
sign := encodeURIComponent(authorization) sign := encodeURIComponent(authorization, []byte{'&','='})
if req.URL.RawQuery == "" { if req.URL.RawQuery == "" {
req.URL.RawQuery = fmt.Sprintf("sign=%s", sign) req.URL.RawQuery = fmt.Sprintf("%s", sign)
} else { } else {
req.URL.RawQuery = fmt.Sprintf("%s&sign=%s", req.URL.RawQuery, sign) req.URL.RawQuery = fmt.Sprintf("%s&%s", req.URL.RawQuery, sign)
} }
return req.URL, nil return req.URL, nil
@@ -256,20 +256,26 @@ func (s *ObjectService) Copy(ctx context.Context, name, sourceURL string, opt *O
} }
var res ObjectCopyResult var res ObjectCopyResult
if opt == nil { copyOpt := &ObjectCopyOptions{
opt = new(ObjectCopyOptions) &ObjectCopyHeaderOptions{},
&ACLHeaderOptions{},
} }
if opt.ObjectCopyHeaderOptions == nil { if opt != nil {
opt.ObjectCopyHeaderOptions = new(ObjectCopyHeaderOptions) if opt.ObjectCopyHeaderOptions != nil {
*copyOpt.ObjectCopyHeaderOptions = *opt.ObjectCopyHeaderOptions
} }
opt.XCosCopySource = u if opt.ACLHeaderOptions != nil {
*copyOpt.ACLHeaderOptions = *opt.ACLHeaderOptions
}
}
copyOpt.XCosCopySource = u
sendOpt := sendOptions{ sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL, baseURL: s.client.BaseURL.BucketURL,
uri: "/" + encodeURIComponent(name), uri: "/" + encodeURIComponent(name),
method: http.MethodPut, method: http.MethodPut,
body: nil, body: nil,
optHeader: opt, optHeader: copyOpt,
result: &res, result: &res,
} }
resp, err := s.client.send(ctx, &sendOpt) resp, err := s.client.send(ctx, &sendOpt)