update bucket lifecycle,presignedURL,error format
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user