update crc

This commit is contained in:
jojoliang
2021-03-12 13:19:26 +08:00
parent 13b56ff05d
commit 23ad6e2c72
3 changed files with 14 additions and 6 deletions

11
cos.go
View File

@@ -22,7 +22,7 @@ import (
const (
// Version current go sdk version
Version = "0.7.21"
Version = "0.7.22"
userAgent = "cos-go-sdk-v5/" + Version
contentTypeXML = "application/xml"
defaultServiceBaseURL = "http://service.cos.myqcloud.com"
@@ -70,6 +70,10 @@ func NewBucketURL(bucketName, region string, secure bool) *url.URL {
return u
}
type Config struct {
DisableCRC bool
}
// Client is a client manages communication with the COS API.
type Client struct {
client *http.Client
@@ -85,6 +89,8 @@ type Client struct {
Object *ObjectService
Batch *BatchService
CI *CIService
Conf *Config
}
type service struct {
@@ -112,6 +118,9 @@ func NewClient(uri *BaseURL, httpClient *http.Client) *Client {
client: httpClient,
UserAgent: userAgent,
BaseURL: baseURL,
Conf: &Config{
DisableCRC: false,
},
}
c.common.client = c
c.Service = (*ServiceService)(&c.common)

View File

@@ -51,8 +51,7 @@ func main() {
// Case1 多线程上传对象
opt := &cos.MultiUploadOptions{
EnableVerification: true,
ThreadPoolSize: 5,
ThreadPoolSize: 5,
}
v, _, err := c.Object.Upload(
context.Background(), "gomulput1G", "./test1G", opt,

View File

@@ -746,7 +746,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
return nil, nil, err
}
// 校验
if opt.EnableVerification {
if !s.client.Conf.DisableCRC {
fd, err := os.Open(filepath)
if err != nil {
return nil, nil, err
@@ -771,7 +771,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
Key: name,
ETag: rsp.Header.Get("ETag"),
}
if rsp != nil && opt.EnableVerification {
if rsp != nil && !s.client.Conf.DisableCRC {
scoscrc := rsp.Header.Get("x-cos-hash-crc64ecma")
icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64)
if icoscrc != localcrc {
@@ -902,7 +902,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
return v, resp, err
}
if resp != nil && opt.EnableVerification {
if resp != nil && !s.client.Conf.DisableCRC {
scoscrc := resp.Header.Get("x-cos-hash-crc64ecma")
icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64)
if icoscrc != localcrc {