Browse Source
Merge pull request #17 from toranger/master
Add the comment to declare the out of memory issue when put large loc…
tags/v0.7.8
toranger
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
19 additions and
12 deletions
-
example/object/get.go
-
example/object/put.go
-
object.go
|
|
@ -26,7 +26,7 @@ func main() { |
|
|
|
RequestHeader: true, |
|
|
|
RequestBody: true, |
|
|
|
ResponseHeader: true, |
|
|
|
ResponseBody: true, |
|
|
|
ResponseBody: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}) |
|
|
|
|
|
@ -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) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
@ -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 { |
|
|
|