@@ -338,11 +338,25 @@ type CopyPartResult struct {
338338//
339339// https://www.qcloud.com/document/product/436/7750
340340func (s * ObjectService ) CopyPart (ctx context.Context , name , uploadID string , partNumber int , sourceURL string , opt * ObjectCopyPartOptions ) (* CopyPartResult , * Response , error ) {
341- if opt == nil {
342- opt = & ObjectCopyPartOptions {}
341+ if strings . HasPrefix ( sourceURL , "http://" ) || strings . HasPrefix ( sourceURL , "https://" ) {
342+ return nil , nil , errors . New ( "sourceURL format is invalid." )
343343 }
344- opt .XCosCopySource = sourceURL
345- u := fmt .Sprintf ("/%s?partNumber=%d&uploadId=%s" , encodeURIComponent (name ), partNumber , uploadID )
344+ surl := strings .SplitN (sourceURL , "/" , 2 )
345+ if len (surl ) < 2 {
346+ return nil , nil , errors .New (fmt .Sprintf ("x-cos-copy-source format error: %s" , sourceURL ))
347+ }
348+ var u string
349+ keyAndVer := strings .SplitN (surl [1 ], "?" , 2 )
350+ if len (keyAndVer ) < 2 {
351+ u = fmt .Sprintf ("%s/%s" , surl [0 ], encodeURIComponent (surl [1 ], []byte {'/' }))
352+ } else {
353+ u = fmt .Sprintf ("%v/%v?%v" , surl [0 ], encodeURIComponent (keyAndVer [0 ], []byte {'/' }), encodeURIComponent (keyAndVer [1 ], []byte {'=' }))
354+ }
355+
356+ opt = cloneObjectCopyPartOptions (opt )
357+ opt .XCosCopySource = u
358+
359+ u = fmt .Sprintf ("/%s?partNumber=%d&uploadId=%s" , encodeURIComponent (name ), partNumber , uploadID )
346360 var res CopyPartResult
347361 var bs bytes.Buffer
348362 sendOpt := sendOptions {
@@ -511,20 +525,11 @@ func (s *ObjectService) MultiCopy(ctx context.Context, name string, sourceURL st
511525 return nil , nil , err
512526 }
513527 totalBytes := resp .ContentLength
514- surl := strings .SplitN (sourceURL , "/" , 2 )
515- if len (surl ) < 2 {
516- return nil , nil , errors .New (fmt .Sprintf ("x-cos-copy-source format error: %s" , sourceURL ))
517- }
518528 var u string
519529 if len (id ) == 1 {
520- u = fmt .Sprintf ("%s/%s ?versionId=%s" , surl [ 0 ], encodeURIComponent ( surl [ 1 ]) , id [0 ])
530+ u = fmt .Sprintf ("%s?versionId=%s" , sourceURL , id [0 ])
521531 } else if len (id ) == 0 {
522- keyAndVer := strings .SplitN (surl [1 ], "?" , 2 )
523- if len (keyAndVer ) < 2 {
524- u = fmt .Sprintf ("%s/%s" , surl [0 ], encodeURIComponent (surl [1 ]))
525- } else {
526- u = fmt .Sprintf ("%v/%v?%v" , surl [0 ], encodeURIComponent (keyAndVer [0 ], []byte {'/' }), encodeURIComponent (keyAndVer [1 ], []byte {'=' }))
527- }
532+ u = sourceURL
528533 } else {
529534 return nil , nil , errors .New ("wrong params" )
530535 }
@@ -536,6 +541,7 @@ func (s *ObjectService) MultiCopy(ctx context.Context, name string, sourceURL st
536541 if err != nil {
537542 return nil , nil , err
538543 }
544+
539545 if partNum == 0 || (totalBytes <= singleUploadMaxLength && ! opt .useMulti ) {
540546 if len (id ) > 0 {
541547 return s .Copy (ctx , name , sourceURL , opt .OptCopy , id [0 ])
0 commit comments