Browse Source

update latest 0.7.23 stable

master
jojoliang 4 years ago
parent
commit
17c220d588
  1. 9
      ci.go
  2. 14
      helper.go
  3. 9
      object.go
  4. 3
      object_part.go

9
ci.go

@ -206,14 +206,21 @@ func (s *CIService) GetVideoAuditingJob(ctx context.Context, jobid string) (*Get
}
// ci put https://cloud.tencent.com/document/product/460/18147
func (s *CIService) Put(ctx context.Context, name string, r io.Reader, opt *ObjectPutOptions) (*ImageProcessResult, *Response, error) {
func (s *CIService) Put(ctx context.Context, name string, r io.Reader, uopt *ObjectPutOptions) (*ImageProcessResult, *Response, error) {
if err := CheckReaderLen(r); err != nil {
return nil, nil, err
}
opt := cloneObjectPutOptions(uopt)
totalBytes, err := GetReaderLen(r)
if err != nil && opt != nil && opt.Listener != nil {
return nil, nil, err
}
if err == nil {
// 与 go http 保持一致, 非bytes.Buffer/bytes.Reader/strings.Reader由用户指定ContentLength, 或使用 Chunk 上传
if opt != nil && opt.ContentLength == 0 && IsLenReader(r) {
opt.ContentLength = totalBytes
}
}
reader := TeeReader(r, nil, totalBytes, nil)
if s.client.Conf.EnableCRC {
reader.writer = crc64.New(crc64.MakeTable(crc64.ECMA))

14
helper.go

@ -159,6 +159,20 @@ func GetReaderLen(reader io.Reader) (length int64, err error) {
return
}
func IsLenReader(reader io.Reader) bool {
switch reader.(type) {
case *bytes.Buffer:
return true
case *bytes.Reader:
return true
case *strings.Reader:
return true
default:
return false
}
return false
}
func CheckReaderLen(reader io.Reader) error {
nlen, err := GetReaderLen(reader)
if err != nil || nlen < singleUploadMaxLength {

9
object.go

@ -181,14 +181,21 @@ type ObjectPutOptions struct {
// Put Object请求可以将一个文件(Oject)上传至指定Bucket。
//
// https://www.qcloud.com/document/product/436/7749
func (s *ObjectService) Put(ctx context.Context, name string, r io.Reader, opt *ObjectPutOptions) (*Response, error) {
func (s *ObjectService) Put(ctx context.Context, name string, r io.Reader, uopt *ObjectPutOptions) (*Response, error) {
if err := CheckReaderLen(r); err != nil {
return nil, err
}
opt := cloneObjectPutOptions(uopt)
totalBytes, err := GetReaderLen(r)
if err != nil && opt != nil && opt.Listener != nil {
return nil, err
}
if err == nil {
// 与 go http 保持一致, 非bytes.Buffer/bytes.Reader/strings.Reader由用户指定ContentLength, 或使用 Chunk 上传
if opt != nil && opt.ContentLength == 0 && IsLenReader(r) {
opt.ContentLength = totalBytes
}
}
reader := TeeReader(r, nil, totalBytes, nil)
if s.client.Conf.EnableCRC {
reader.writer = crc64.New(crc64.MakeTable(crc64.ECMA))

3
object_part.go

@ -81,7 +81,8 @@ func (s *ObjectService) UploadPart(ctx context.Context, name, uploadID string, p
}
// 分块上传不支持 Chunk 上传
if err == nil {
if opt != nil && opt.ContentLength == 0 {
// 与 go http 保持一致, 非bytes.Buffer/bytes.Reader/strings.Reader需用户指定ContentLength
if opt != nil && opt.ContentLength == 0 && IsLenReader(r) {
opt.ContentLength = totalBytes
}
}

Loading…
Cancel
Save