Browse Source

update crc

master
jojoliang 4 years ago
parent
commit
23ad6e2c72
  1. 11
      cos.go
  2. 3
      example/object/upload.go
  3. 6
      object.go

11
cos.go

@ -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)

3
example/object/upload.go

@ -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,

6
object.go

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

Loading…
Cancel
Save