update crc
This commit is contained in:
11
cos.go
11
cos.go
@@ -22,7 +22,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// Version current go sdk version
|
// Version current go sdk version
|
||||||
Version = "0.7.21"
|
Version = "0.7.22"
|
||||||
userAgent = "cos-go-sdk-v5/" + Version
|
userAgent = "cos-go-sdk-v5/" + Version
|
||||||
contentTypeXML = "application/xml"
|
contentTypeXML = "application/xml"
|
||||||
defaultServiceBaseURL = "http://service.cos.myqcloud.com"
|
defaultServiceBaseURL = "http://service.cos.myqcloud.com"
|
||||||
@@ -70,6 +70,10 @@ func NewBucketURL(bucketName, region string, secure bool) *url.URL {
|
|||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
DisableCRC bool
|
||||||
|
}
|
||||||
|
|
||||||
// Client is a client manages communication with the COS API.
|
// Client is a client manages communication with the COS API.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
@@ -85,6 +89,8 @@ type Client struct {
|
|||||||
Object *ObjectService
|
Object *ObjectService
|
||||||
Batch *BatchService
|
Batch *BatchService
|
||||||
CI *CIService
|
CI *CIService
|
||||||
|
|
||||||
|
Conf *Config
|
||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
@@ -112,6 +118,9 @@ func NewClient(uri *BaseURL, httpClient *http.Client) *Client {
|
|||||||
client: httpClient,
|
client: httpClient,
|
||||||
UserAgent: userAgent,
|
UserAgent: userAgent,
|
||||||
BaseURL: baseURL,
|
BaseURL: baseURL,
|
||||||
|
Conf: &Config{
|
||||||
|
DisableCRC: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
c.common.client = c
|
c.common.client = c
|
||||||
c.Service = (*ServiceService)(&c.common)
|
c.Service = (*ServiceService)(&c.common)
|
||||||
|
|||||||
@@ -51,8 +51,7 @@ func main() {
|
|||||||
|
|
||||||
// Case1 多线程上传对象
|
// Case1 多线程上传对象
|
||||||
opt := &cos.MultiUploadOptions{
|
opt := &cos.MultiUploadOptions{
|
||||||
EnableVerification: true,
|
ThreadPoolSize: 5,
|
||||||
ThreadPoolSize: 5,
|
|
||||||
}
|
}
|
||||||
v, _, err := c.Object.Upload(
|
v, _, err := c.Object.Upload(
|
||||||
context.Background(), "gomulput1G", "./test1G", opt,
|
context.Background(), "gomulput1G", "./test1G", opt,
|
||||||
|
|||||||
@@ -746,7 +746,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
// 校验
|
// 校验
|
||||||
if opt.EnableVerification {
|
if !s.client.Conf.DisableCRC {
|
||||||
fd, err := os.Open(filepath)
|
fd, err := os.Open(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@@ -771,7 +771,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
|
|||||||
Key: name,
|
Key: name,
|
||||||
ETag: rsp.Header.Get("ETag"),
|
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")
|
scoscrc := rsp.Header.Get("x-cos-hash-crc64ecma")
|
||||||
icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64)
|
icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64)
|
||||||
if icoscrc != localcrc {
|
if icoscrc != localcrc {
|
||||||
@@ -902,7 +902,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
|
|||||||
return v, resp, err
|
return v, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp != nil && opt.EnableVerification {
|
if resp != nil && !s.client.Conf.DisableCRC {
|
||||||
scoscrc := resp.Header.Get("x-cos-hash-crc64ecma")
|
scoscrc := resp.Header.Get("x-cos-hash-crc64ecma")
|
||||||
icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64)
|
icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64)
|
||||||
if icoscrc != localcrc {
|
if icoscrc != localcrc {
|
||||||
|
|||||||
Reference in New Issue
Block a user