复制多版本对象

更新时间: 2019-03-14 10:05

您可以通过ObsClient.CopyObject接口传入版本号(CopySourceVersionId)来复制多版本对象,示例代码如下:

  1. // 引入依赖包
  2. import (
  3. "fmt"
  4. "obs"
  5. )
  6.  
  7. var ak = "*** Provide your Access Key ***"
  8. var sk = "*** Provide your Secret Key ***"
  9. var endpoint = "https://your-endpoint"
  10.  
  11. // 创建ObsClient结构体
  12. var obsClient, _ = obs.New(ak, sk, endpoint)
  13.  
  14. func main() {
  15. input := &obs.CopyObjectInput{}
  16. input.Bucket = "destbucketname"
  17. input.Key = "destobjectkey"
  18. input.CopySourceBucket = "sourcebucketname"
  19. input.CopySourceKey = "sourceobjectkey"
  20. // 设置要复制对象的版本号
  21. input.CopySourceVersionId = "versionid"
  22. output, err := obsClient.CopyObject(input)
  23. if err == nil {
  24. fmt.Printf("RequestId:%s\n", output.RequestId)
  25. } else if obsError, ok := err.(obs.ObsError); ok {
  26. fmt.Printf("Code:%s\n", obsError.Code)
  27. fmt.Printf("Message:%s\n", obsError.Message)
  28. }
  29. }

父主题:多版本控制