update bucket lifecycle,presignedURL,error format

This commit is contained in:
jojoliang
2021-04-25 16:05:18 +08:00
parent ca08d6e1a9
commit ae3e31a216
5 changed files with 65 additions and 6 deletions

View File

@@ -29,6 +29,7 @@ func main() {
name := "exampleobject"
ctx := context.Background()
// 方法1 通过 tag 设置 x-cos-security-token
// Get presigned
presignedURL, err := c.Object.GetPresignedURL(ctx, http.MethodGet, name, tak, tsk, time.Hour, token)
if err != nil {
@@ -36,9 +37,32 @@ func main() {
return
}
// Get object by presinged url
_, err = http.Get(presignedURL.String())
resp, err := http.Get(presignedURL.String())
if err != nil {
fmt.Printf("Error: %v\n", err)
}
defer resp.Body.Close()
fmt.Println(presignedURL.String())
fmt.Printf("resp:%v\n", resp)
// 方法2 通过 PresignedURLOptions 设置 x-cos-security-token
opt := &cos.PresignedURLOptions{
Query: &url.Values{},
Header: &http.Header{},
}
opt.Query.Add("x-cos-security-token", "<token>")
// Get presigned
presignedURL, err = c.Object.GetPresignedURL(ctx, http.MethodGet, name, tak, tsk, time.Hour, opt)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
// Get object by presinged url
resp, err = http.Get(presignedURL.String())
if err != nil {
fmt.Printf("Error: %v\n", err)
}
defer resp.Body.Close()
fmt.Println(presignedURL.String())
fmt.Printf("resp:%v\n", resp)
}