Skip to content

Commit

Permalink
update PutFromFile
Browse files Browse the repository at this point in the history
  • Loading branch information
jojoliang committed Mar 26, 2021
1 parent 228fb17 commit 5672500
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,24 @@ func (s *ObjectService) Put(ctx context.Context, name string, r io.Reader, uopt

// PutFromFile put object from local file
// 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
func (s *ObjectService) PutFromFile(ctx context.Context, name string, filePath string, opt *ObjectPutOptions) (resp *Response, err error) {
nr := 0
for nr < 3 {
var fd *os.File
fd, err = os.Open(filePath)
if err != nil {
return
}
resp, err = s.Put(ctx, name, fd, opt)
if err != nil {
nr++
fd.Close()
continue
}
fd.Close()
break
}
defer fd.Close()

return s.Put(ctx, name, fd, opt)
return
}

// ObjectCopyHeaderOptions is the head option of the Copy
Expand Down

0 comments on commit 5672500

Please sign in to comment.