Browse Source

Merge pull request #17 from toranger/master

Add the comment to declare the out of memory issue when put large loc…
tags/v0.7.8
toranger 6 years ago
committed by GitHub
parent
commit
e1400d2554
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      example/object/get.go
  2. 11
      example/object/put.go
  3. 18
      object.go

2
example/object/get.go

@ -26,7 +26,7 @@ func main() {
RequestHeader: true,
RequestBody: true,
ResponseHeader: true,
ResponseBody: true,
ResponseBody: false,
},
},
})

11
example/object/put.go

@ -20,8 +20,9 @@ func main() {
SecretID: os.Getenv("COS_SECRETID"),
SecretKey: os.Getenv("COS_SECRETKEY"),
Transport: &debug.DebugRequestTransport{
RequestHeader: true,
RequestBody: true,
RequestHeader: true,
// Notice when put a large file and set need the request body, might happend out of memory error.
RequestBody: false,
ResponseHeader: true,
ResponseBody: true,
},
@ -54,4 +55,10 @@ func main() {
panic(err)
}
// Case3 put object by local file path
_, err = c.Object.PutFromFile(context.Background(), name, "./test", nil)
if err != nil {
panic(err)
}
}

18
object.go

@ -105,17 +105,17 @@ func (s *ObjectService) Put(ctx context.Context, name string, r io.Reader, opt *
return resp, err
}
// TODO Not Suggest use for now, need to improve
// PutFromFile put object from local file
// func (s *ObjectService) PutFromFile(ctx context.Context, name string, filePath string, opt *ObjectPutOptions) (*Response, error) {
// fd, err := os.Open(filePath)
// if err != nil {
// return nil, err
// }
// defer fd.Close()
// Notice that when use this put large file need set non-body of debug req/resp, otherwise will out of memory
func (s *ObjectService) PutFromFile(ctx context.Context, name string, filePath string, opt *ObjectPutOptions) (*Response, error) {
fd, err := os.Open(filePath)
if err != nil {
return nil, err
}
defer fd.Close()
// return s.Put(ctx, name, fd, opt)
// }
return s.Put(ctx, name, fd, opt)
}
// ObjectCopyHeaderOptions is the head option of the Copy
type ObjectCopyHeaderOptions struct {

Loading…
Cancel
Save