From 17c5ed144fc76384e8f694db692b2818995ea3c9 Mon Sep 17 00:00:00 2001 From: jojoliang Date: Mon, 31 Aug 2020 21:49:52 +0800 Subject: [PATCH] =?UTF-8?q?x-cos-copy-source=20urlencode=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cos.go | 2 +- object.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cos.go b/cos.go index cf5f02b..bdca0c9 100644 --- a/cos.go +++ b/cos.go @@ -21,7 +21,7 @@ import ( const ( // Version current go sdk version - Version = "0.7.7" + Version = "0.7.8" userAgent = "cos-go-sdk-v5/" + Version contentTypeXML = "application/xml" defaultServiceBaseURL = "http://service.cos.myqcloud.com" diff --git a/object.go b/object.go index 3c35eca..60864df 100644 --- a/object.go +++ b/object.go @@ -10,6 +10,7 @@ import ( "net/url" "os" "sort" + "strings" "time" ) @@ -236,11 +237,15 @@ type ObjectCopyResult struct { // // https://cloud.tencent.com/document/product/436/10881 func (s *ObjectService) Copy(ctx context.Context, name, sourceURL string, opt *ObjectCopyOptions, id ...string) (*ObjectCopyResult, *Response, error) { + surl := strings.SplitN(sourceURL, "/", 2) + if len(surl) < 2 { + return nil, nil, errors.New(fmt.Sprintf("x-cos-copy-source format error: %s", sourceURL)) + } var u string if len(id) == 1 { - u = fmt.Sprintf("%s?versionId=%s", encodeURIComponent(sourceURL), id[0]) + u = fmt.Sprintf("%s/%s?versionId=%s", surl[0], encodeURIComponent(surl[1]), id[0]) } else if len(id) == 0 { - u = encodeURIComponent(sourceURL) + u = fmt.Sprintf("%s/%s", surl[0], encodeURIComponent(surl[1])) } else { return nil, nil, errors.New("wrong params") }