Skip to content

Commit 5672500

Browse files
author
jojoliang
committed
update PutFromFile
1 parent 228fb17 commit 5672500

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

object.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,24 @@ func (s *ObjectService) Put(ctx context.Context, name string, r io.Reader, uopt
217217

218218
// PutFromFile put object from local file
219219
// Notice that when use this put large file need set non-body of debug req/resp, otherwise will out of memory
220-
func (s *ObjectService) PutFromFile(ctx context.Context, name string, filePath string, opt *ObjectPutOptions) (*Response, error) {
221-
fd, err := os.Open(filePath)
222-
if err != nil {
223-
return nil, err
220+
func (s *ObjectService) PutFromFile(ctx context.Context, name string, filePath string, opt *ObjectPutOptions) (resp *Response, err error) {
221+
nr := 0
222+
for nr < 3 {
223+
var fd *os.File
224+
fd, err = os.Open(filePath)
225+
if err != nil {
226+
return
227+
}
228+
resp, err = s.Put(ctx, name, fd, opt)
229+
if err != nil {
230+
nr++
231+
fd.Close()
232+
continue
233+
}
234+
fd.Close()
235+
break
224236
}
225-
defer fd.Close()
226-
227-
return s.Put(ctx, name, fd, opt)
237+
return
228238
}
229239

230240
// ObjectCopyHeaderOptions is the head option of the Copy

0 commit comments

Comments
 (0)