From 4257d33afb6b106145d2ab1b7443b180cc516355 Mon Sep 17 00:00:00 2001 From: jojoliang Date: Mon, 22 Jul 2024 19:42:57 +0800 Subject: [PATCH] update presignedurl demo --- example/object/getByPresignedURL.go | 19 +------------------ example/object/getByPresignedURL2.go | 12 ------------ example/object/presigned_url_with_token.go | 14 -------------- 3 files changed, 1 insertion(+), 44 deletions(-) diff --git a/example/object/getByPresignedURL.go b/example/object/getByPresignedURL.go index d8bae12..6a53526 100644 --- a/example/object/getByPresignedURL.go +++ b/example/object/getByPresignedURL.go @@ -1,10 +1,8 @@ package main import ( - "bytes" "context" "fmt" - "io/ioutil" "net/http" "net/url" "os" @@ -55,23 +53,8 @@ func main() { name := "test" ctx := context.Background() - // Normal header way to get object - resp, err := c.Object.Get(ctx, name, nil) - log_status(err) - bs, _ := ioutil.ReadAll(resp.Body) - resp.Body.Close() - // Get presigned presignedURL, err := c.Object.GetPresignedURL(ctx, http.MethodGet, name, ak, sk, time.Hour, nil) log_status(err) - - // Get object by presinged url - resp2, err := http.Get(presignedURL.String()) - log_status(err) - bs2, _ := ioutil.ReadAll(resp2.Body) - resp2.Body.Close() - fmt.Printf("result2 is : %s\n", string(bs2)) - - fmt.Printf("%v\n\n", bytes.Compare(bs2, bs) == 0) - + fmt.Println(presignedURL.String()) } diff --git a/example/object/getByPresignedURL2.go b/example/object/getByPresignedURL2.go index ee17ada..00ebc74 100644 --- a/example/object/getByPresignedURL2.go +++ b/example/object/getByPresignedURL2.go @@ -7,7 +7,6 @@ import ( "net/http" "net/url" "os" - "strings" "time" ) @@ -35,15 +34,4 @@ func main() { return } fmt.Printf("url: %v\n", presignedURL.String()) - // 通过预签名方式上传对象 - data := "test upload with presignedURL" - f := strings.NewReader(data) - req, err := http.NewRequest(http.MethodPut, presignedURL.String(), f) - if err != nil { - fmt.Printf("Error: %v\n", err) - } - _, err = http.DefaultClient.Do(req) - if err != nil { - fmt.Printf("Error: %v\n", err) - } } diff --git a/example/object/presigned_url_with_token.go b/example/object/presigned_url_with_token.go index 0e92187..f3cea9e 100644 --- a/example/object/presigned_url_with_token.go +++ b/example/object/presigned_url_with_token.go @@ -36,14 +36,7 @@ func main() { 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) // 方法2 通过 PresignedURLOptions 设置 x-cos-security-token opt := &cos.PresignedURLOptions{ @@ -57,12 +50,5 @@ func main() { 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) }