Skip to content

Commit 31af2de

Browse files
authored
Merge pull request #83 from agin719/common-dev
x-cos-copy-source urlencode修正
2 parents e870e71 + 17c5ed1 commit 31af2de

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

cos.go

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

2222
const (
2323
// Version current go sdk version
24-
Version = "0.7.7"
24+
Version = "0.7.8"
2525
userAgent = "cos-go-sdk-v5/" + Version
2626
contentTypeXML = "application/xml"
2727
defaultServiceBaseURL = "http://service.cos.myqcloud.com"

object.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/url"
1111
"os"
1212
"sort"
13+
"strings"
1314
"time"
1415
)
1516

@@ -236,11 +237,15 @@ type ObjectCopyResult struct {
236237
//
237238
// https://cloud.tencent.com/document/product/436/10881
238239
func (s *ObjectService) Copy(ctx context.Context, name, sourceURL string, opt *ObjectCopyOptions, id ...string) (*ObjectCopyResult, *Response, error) {
240+
surl := strings.SplitN(sourceURL, "/", 2)
241+
if len(surl) < 2 {
242+
return nil, nil, errors.New(fmt.Sprintf("x-cos-copy-source format error: %s", sourceURL))
243+
}
239244
var u string
240245
if len(id) == 1 {
241-
u = fmt.Sprintf("%s?versionId=%s", encodeURIComponent(sourceURL), id[0])
246+
u = fmt.Sprintf("%s/%s?versionId=%s", surl[0], encodeURIComponent(surl[1]), id[0])
242247
} else if len(id) == 0 {
243-
u = encodeURIComponent(sourceURL)
248+
u = fmt.Sprintf("%s/%s", surl[0], encodeURIComponent(surl[1]))
244249
} else {
245250
return nil, nil, errors.New("wrong params")
246251
}

0 commit comments

Comments
 (0)