Browse Source
Merge pull request #63 from agin719/cod-dev
update MultiUpload
tags/v0.7.8
agin719
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
48 additions and
2 deletions
-
example/object/upload.go
-
object.go
|
|
@ -0,0 +1,40 @@ |
|
|
|
package main |
|
|
|
|
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"net/http" |
|
|
|
"net/url" |
|
|
|
"os" |
|
|
|
"time" |
|
|
|
|
|
|
|
"fmt" |
|
|
|
"github.com/tencentyun/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) |
|
|
|
} |
|
|
@ -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) MultiUpload(ctx context.Context, name string, filepath string, opt *MultiUploadOptions) (*CompleteMultipartUploadResult, *Response, error) { |
|
|
|
return s.Upload(ctx, name, filepath, opt) |
|
|
|
} |
|
|
|
|
|
|
|
func (s *ObjectService) Upload(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 { |
|
|
|