update rm the append interface
This commit is contained in:
@@ -78,7 +78,6 @@ Bucket API:
|
|||||||
|
|
||||||
Object API:
|
Object API:
|
||||||
|
|
||||||
* [x] Append Object(使用示例:[object/append.go](./example/object/append.go))
|
|
||||||
* [x] Get Object(使用示例:[object/get.go](./example/object/get.go))
|
* [x] Get Object(使用示例:[object/get.go](./example/object/get.go))
|
||||||
* [x] Get Object ACL(使用示例:[object/getACL.go](./example/object/getACL.go))
|
* [x] Get Object ACL(使用示例:[object/getACL.go](./example/object/getACL.go))
|
||||||
* [x] Put Object(使用示例:[object/put.go](./example/object/put.go))
|
* [x] Put Object(使用示例:[object/put.go](./example/object/put.go))
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"math/rand"
|
|
||||||
"net/url"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/tencentyun/cos-go-sdk-v5"
|
|
||||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
|
||||||
)
|
|
||||||
|
|
||||||
func genBigData(blockSize int) []byte {
|
|
||||||
b := make([]byte, blockSize)
|
|
||||||
if _, err := rand.Read(b); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
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: false,
|
|
||||||
ResponseHeader: true,
|
|
||||||
ResponseBody: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
startTime := time.Now()
|
|
||||||
|
|
||||||
name := fmt.Sprintf("test/test_object_append_%s", startTime.Format(time.RFC3339))
|
|
||||||
data := genBigData(1024 * 1024 * 1)
|
|
||||||
length := len(data)
|
|
||||||
r := bytes.NewReader(data)
|
|
||||||
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
// 第一次就必须 append
|
|
||||||
resp, err := c.Object.Append(ctx, name, 0, r, nil)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("%s\n", resp.Status)
|
|
||||||
|
|
||||||
// head
|
|
||||||
if _, err = c.Object.Head(ctx, name, nil); err != nil {
|
|
||||||
panic(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 再次 append
|
|
||||||
data = genBigData(1024 * 1024 * 5)
|
|
||||||
r = bytes.NewReader(data)
|
|
||||||
resp, err = c.Object.Append(context.Background(), name, length, r, nil)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
fmt.Printf("%s\n", resp.Status)
|
|
||||||
}
|
|
||||||
37
object.go
37
object.go
@@ -169,7 +169,7 @@ func (s *ObjectService) Head(ctx context.Context, name string, opt *ObjectHeadOp
|
|||||||
optHeader: opt,
|
optHeader: opt,
|
||||||
}
|
}
|
||||||
resp, err := s.client.send(ctx, &sendOpt)
|
resp, err := s.client.send(ctx, &sendOpt)
|
||||||
if (resp.Header["X-Cos-Object-Type"] != nil && resp.Header["X-Cos-Object-Type"][0] == "appendable") {
|
if resp.Header["X-Cos-Object-Type"] != nil && resp.Header["X-Cos-Object-Type"][0] == "appendable" {
|
||||||
resp.Header.Add("x-cos-next-append-position", resp.Header["Content-Length"][0])
|
resp.Header.Add("x-cos-next-append-position", resp.Header["Content-Length"][0])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,6 +200,7 @@ func (s *ObjectService) Options(ctx context.Context, name string, opt *ObjectOpt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Append ...
|
// Append ...
|
||||||
|
// TODO Append 接口在优化未开放使用
|
||||||
//
|
//
|
||||||
// Append请求可以将一个文件(Object)以分块追加的方式上传至 Bucket 中。使用Append Upload的文件必须事前被设定为Appendable。
|
// Append请求可以将一个文件(Object)以分块追加的方式上传至 Bucket 中。使用Append Upload的文件必须事前被设定为Appendable。
|
||||||
// 当Appendable的文件被执行Put Object的操作以后,文件被覆盖,属性改变为Normal。
|
// 当Appendable的文件被执行Put Object的操作以后,文件被覆盖,属性改变为Normal。
|
||||||
@@ -214,21 +215,21 @@ func (s *ObjectService) Options(ctx context.Context, name string, opt *ObjectOpt
|
|||||||
// 当 r 不是 bytes.Buffer/bytes.Reader/strings.Reader 时,必须指定 opt.ObjectPutHeaderOptions.ContentLength
|
// 当 r 不是 bytes.Buffer/bytes.Reader/strings.Reader 时,必须指定 opt.ObjectPutHeaderOptions.ContentLength
|
||||||
//
|
//
|
||||||
// https://www.qcloud.com/document/product/436/7741
|
// https://www.qcloud.com/document/product/436/7741
|
||||||
func (s *ObjectService) Append(ctx context.Context, name string, position int, r io.Reader, opt *ObjectPutOptions) (*Response, error) {
|
// func (s *ObjectService) Append(ctx context.Context, name string, position int, r io.Reader, opt *ObjectPutOptions) (*Response, error) {
|
||||||
u := fmt.Sprintf("/%s?append&position=%d", encodeURIComponent(name), position)
|
// u := fmt.Sprintf("/%s?append&position=%d", encodeURIComponent(name), position)
|
||||||
if position != 0{
|
// if position != 0{
|
||||||
opt = nil
|
// opt = nil
|
||||||
}
|
// }
|
||||||
sendOpt := sendOptions{
|
// sendOpt := sendOptions{
|
||||||
baseURL: s.client.BaseURL.BucketURL,
|
// baseURL: s.client.BaseURL.BucketURL,
|
||||||
uri: u,
|
// uri: u,
|
||||||
method: http.MethodPost,
|
// method: http.MethodPost,
|
||||||
optHeader: opt,
|
// optHeader: opt,
|
||||||
body: r,
|
// body: r,
|
||||||
}
|
// }
|
||||||
resp, err := s.client.send(ctx, &sendOpt)
|
// resp, err := s.client.send(ctx, &sendOpt)
|
||||||
return resp, err
|
// return resp, err
|
||||||
}
|
// }
|
||||||
|
|
||||||
// ObjectDeleteMultiOptions ...
|
// ObjectDeleteMultiOptions ...
|
||||||
type ObjectDeleteMultiOptions struct {
|
type ObjectDeleteMultiOptions struct {
|
||||||
@@ -297,7 +298,9 @@ func (s *ObjectService) MultiUpload(ctx context.Context, name string, r io.Reade
|
|||||||
|
|
||||||
optini := opt.OptIni
|
optini := opt.OptIni
|
||||||
res, _, err := s.InitiateMultipartUpload(ctx, name, optini)
|
res, _, err := s.InitiateMultipartUpload(ctx, name, optini)
|
||||||
if err != nil{panic(err)}
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
uploadID := res.UploadID
|
uploadID := res.UploadID
|
||||||
bufSize := opt.PartSize * 1024 * 1024
|
bufSize := opt.PartSize * 1024 * 1024
|
||||||
buffer := make([]byte, bufSize)
|
buffer := make([]byte, bufSize)
|
||||||
|
|||||||
Reference in New Issue
Block a user