Skip to content

Commit

Permalink
Add the comment to declare the out of memory issue when put large loc…
Browse files Browse the repository at this point in the history
…al file
  • Loading branch information
vintmd committed Jan 31, 2019
1 parent bf9ab1f commit 6c894b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion example/object/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
RequestHeader: true,
RequestBody: true,
ResponseHeader: true,
ResponseBody: true,
ResponseBody: false,
},
},
})
Expand Down
11 changes: 9 additions & 2 deletions example/object/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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 changes: 9 additions & 9 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6c894b8

Please sign in to comment.