package main import ( "context" "fmt" "net/http" "net/url" "os" "time" "github.com/tencentyun/cos-go-sdk-v5" ) type URLToken struct { SessionToken string `url:"x-cos-security-token,omitempty" header:"-"` } func main() { // 替换成您的临时密钥 tak := os.Getenv("COS_SECRETID") tsk := os.Getenv("COS_SECRETKEY") token := &URLToken{ SessionToken: "", } u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com") b := &cos.BaseURL{BucketURL: u} c := cos.NewClient(b, &http.Client{}) name := "exampleobject" ctx := context.Background() // Get presigned presignedURL, err := c.Object.GetPresignedURL(ctx, http.MethodGet, name, tak, tsk, time.Hour, token) if err != nil { fmt.Printf("Error: %v\n", err) return } // Get object by presinged url _, err = http.Get(presignedURL.String()) if err != nil { fmt.Printf("Error: %v\n", err) } fmt.Println(presignedURL.String()) }