Browse Source

Merge pull request #21 from toranger/master

Add PostObjectRestore interface
tags/v0.7.8
Yan junming 6 years ago
committed by GitHub
parent
commit
4b379cf5c4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      costesting/ci_test.go
  2. 41
      example/object/restore.go
  3. 28
      object.go

27
costesting/ci_test.go

@ -334,6 +334,33 @@ func (s *CosTestSuite) TestPutGetObjectACL() {
assert.Nil(s.T(), err, "DeleteObject Failed")
}
func (s *CosTestSuite) TestPutObjectRestore() {
name := "archivetest"
putOpt := &cos.ObjectPutOptions{
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
XCosStorageClass: "ARCHIVE",
},
}
f := strings.NewReader("test")
_, err := s.Client.Object.Put(context.Background(), name, f, putOpt)
assert.Nil(s.T(), err, "PutObject Archive faild")
opt := &cos.ObjectRestoreOptions{
Days: 2,
Tier: &cos.CASJobParameters{
// Standard, Exepdited and Bulk
Tier: "Expedited",
},
}
resp, _ := s.Client.Object.PutRestore(context.Background(), name, opt)
retCode := resp.StatusCode
if retCode != 200 && retCode != 202 && retCode != 409 {
right := false
fmt.Println("PutObjectRestore get code is:", retCode)
assert.Equal(s.T(), true, right, "PutObjectRestore Failed")
}
}
func (s *CosTestSuite) TestCopyObject() {
u := "http://gosdkcopytest-" + s.Appid + ".cos.ap-beijing-1.myqcloud.com"
iu, _ := url.Parse(u)

41
example/object/restore.go

@ -0,0 +1,41 @@
package main
import (
"context"
"net/http"
"net/url"
"os"
"github.com/tencentyun/cos-go-sdk-v5"
"github.com/tencentyun/cos-go-sdk-v5/debug"
)
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
c := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
SecretID: os.Getenv("COS_SECRETID"),
SecretKey: os.Getenv("COS_SECRETKEY"),
Transport: &debug.DebugRequestTransport{
RequestHeader: true,
RequestBody: true,
ResponseHeader: true,
ResponseBody: true,
},
},
})
opt := &cos.ObjectRestoreOptions{
Days: 2,
Tier: &cos.CASJobParameters{
// Standard, Exepdited and Bulk
Tier: "Expedited",
},
}
name := "archivetest"
_, err := c.Object.PutRestore(context.Background(), name, opt)
if err != nil {
panic(err)
}
}

28
object.go

@ -232,6 +232,34 @@ func (s *ObjectService) Options(ctx context.Context, name string, opt *ObjectOpt
return resp, err
}
// CASJobParameters support three way: Standard(in 35 hours), Expedited(quick way, in 15 mins), Bulk(in 5-12 hours_
type CASJobParameters struct {
Tier string `xml:"Tier"`
}
// ObjectRestoreOptions is the option of object restore
type ObjectRestoreOptions struct {
XMLName xml.Name `xml:"RestoreRequest"`
Days int `xml:"Days"`
Tier *CASJobParameters `xml:"CASJobParameters"`
}
// PutRestore API can recover an object of type archived by COS archive.
//
// https://cloud.tencent.com/document/product/436/12633
func (s *ObjectService) PutRestore(ctx context.Context, name string, opt *ObjectRestoreOptions) (*Response, error) {
u := fmt.Sprintf("/%s?restore", encodeURIComponent(name))
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: u,
method: http.MethodPost,
body: opt,
}
resp, err := s.client.send(ctx, &sendOpt)
return resp, err
}
// TODO Append 接口在优化未开放使用
//
// Append请求可以将一个文件(Object)以分块追加的方式上传至 Bucket 中。使用Append Upload的文件必须事前被设定为Appendable。

Loading…
Cancel
Save