Browse Source

update MultiUpload

tags/v0.7.8
agin719 5 years ago
parent
commit
2258d2c729
  1. 40
      example/object/upload.go
  2. 8
      object.go

40
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)
}

8
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 {

Loading…
Cancel
Save