From 2258d2c7294cb95286e6dcc742cd8f4b06182cdc Mon Sep 17 00:00:00 2001 From: agin719 Date: Mon, 9 Dec 2019 08:36:48 -0800 Subject: [PATCH 1/2] update MultiUpload --- example/object/upload.go | 40 ++++++++++++++++++++++++++++++++++++++++ object.go | 8 +++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 example/object/upload.go diff --git a/example/object/upload.go b/example/object/upload.go new file mode 100644 index 0000000..01a6bf2 --- /dev/null +++ b/example/object/upload.go @@ -0,0 +1,40 @@ +package main + +import ( + "context" + "net/http" + "net/url" + "os" + "time" + + "fmt" + "github.com/agin719/cos-go-sdk-v5" + "github.com/tencentyun/cos-go-sdk-v5/debug" +) + +func main() { + u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com") + b := &cos.BaseURL{BucketURL: u} + c := cos.NewClient(b, &http.Client{ + //设置超时时间 + Timeout: 100 * time.Second, + Transport: &cos.AuthorizationTransport{ + SecretID: os.Getenv("COS_SECRETID"), + SecretKey: os.Getenv("COS_SECRETKEY"), + Transport: &debug.DebugRequestTransport{ + RequestHeader: false, + RequestBody: false, + ResponseHeader: false, + ResponseBody: false, + }, + }, + }) + + v, _, err := c.Object.Upload( + context.Background(), "gomulput1G", "./test1G", nil, + ) + if err != nil { + panic(err) + } + fmt.Println(v) +} diff --git a/object.go b/object.go index 87480b3..e052e64 100644 --- a/object.go +++ b/object.go @@ -574,14 +574,20 @@ func SplitFileIntoChunks(filePath string, partSize int64) ([]Chunk, int, error) } -// MultiUpload 为高级upload接口,并发分块上传 +// MultiUpload/Upload 为高级upload接口,并发分块上传 // 注意该接口目前只供参考 // // 当 partSize > 0 时,由调用者指定分块大小,否则由 SDK 自动切分,单位为MB // 由调用者指定分块大小时,请确认分块数量不超过10000 // +func (s *ObjectService) Upload(ctx context.Context, name string, filepath string, opt *MultiUploadOptions) (*CompleteMultipartUploadResult, *Response, error) { + return s.MultiUpload(ctx, name, filepath, opt) +} func (s *ObjectService) MultiUpload(ctx context.Context, name string, filepath string, opt *MultiUploadOptions) (*CompleteMultipartUploadResult, *Response, error) { + if opt == nil { + opt = &MultiUploadOptions{} + } // 1.Get the file chunk chunks, partNum, err := SplitFileIntoChunks(filepath, opt.PartSize) if err != nil { From 04717c1144ffe0f6d8fe92c441f56f1e4a2944e2 Mon Sep 17 00:00:00 2001 From: agin719 Date: Mon, 9 Dec 2019 08:42:21 -0800 Subject: [PATCH 2/2] update MultiUpload --- example/object/upload.go | 2 +- object.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/example/object/upload.go b/example/object/upload.go index 01a6bf2..4f055d2 100644 --- a/example/object/upload.go +++ b/example/object/upload.go @@ -8,7 +8,7 @@ import ( "time" "fmt" - "github.com/agin719/cos-go-sdk-v5" + "github.com/tencentyun/cos-go-sdk-v5" "github.com/tencentyun/cos-go-sdk-v5/debug" ) diff --git a/object.go b/object.go index e052e64..0a25805 100644 --- a/object.go +++ b/object.go @@ -580,11 +580,11 @@ func SplitFileIntoChunks(filePath string, partSize int64) ([]Chunk, int, error) // 当 partSize > 0 时,由调用者指定分块大小,否则由 SDK 自动切分,单位为MB // 由调用者指定分块大小时,请确认分块数量不超过10000 // -func (s *ObjectService) Upload(ctx context.Context, name string, filepath string, opt *MultiUploadOptions) (*CompleteMultipartUploadResult, *Response, error) { - return s.MultiUpload(ctx, name, filepath, opt) +func (s *ObjectService) MultiUpload(ctx context.Context, name string, filepath string, opt *MultiUploadOptions) (*CompleteMultipartUploadResult, *Response, error) { + return s.Upload(ctx, name, filepath, opt) } -func (s *ObjectService) MultiUpload(ctx context.Context, name string, filepath string, opt *MultiUploadOptions) (*CompleteMultipartUploadResult, *Response, error) { +func (s *ObjectService) Upload(ctx context.Context, name string, filepath string, opt *MultiUploadOptions) (*CompleteMultipartUploadResult, *Response, error) { if opt == nil { opt = &MultiUploadOptions{} }