update PutFromFile
This commit is contained in:
24
object.go
24
object.go
@@ -217,14 +217,24 @@ func (s *ObjectService) Put(ctx context.Context, name string, r io.Reader, uopt
|
|||||||
|
|
||||||
// PutFromFile put object from local file
|
// 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
|
// 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) {
|
func (s *ObjectService) PutFromFile(ctx context.Context, name string, filePath string, opt *ObjectPutOptions) (resp *Response, err error) {
|
||||||
fd, err := os.Open(filePath)
|
nr := 0
|
||||||
if err != nil {
|
for nr < 3 {
|
||||||
return nil, err
|
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
|
||||||
|
|
||||||
return s.Put(ctx, name, fd, opt)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectCopyHeaderOptions is the head option of the Copy
|
// ObjectCopyHeaderOptions is the head option of the Copy
|
||||||
|
|||||||
Reference in New Issue
Block a user