diff --git a/example/object/get.go b/example/object/get.go index e43a430..e845e45 100644 --- a/example/object/get.go +++ b/example/object/get.go @@ -26,7 +26,7 @@ func main() { RequestHeader: true, RequestBody: true, ResponseHeader: true, - ResponseBody: true, + ResponseBody: false, }, }, }) diff --git a/example/object/put.go b/example/object/put.go index 6952b9c..8fd5839 100644 --- a/example/object/put.go +++ b/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) + } + } diff --git a/object.go b/object.go index 555bdee..791960f 100644 --- a/object.go +++ b/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 {