huaweicloud / huaweicloud-sdk-go-obs

Apache License 2.0
42 stars 24 forks source link

The expiration time of the generated pre-signed URL does not take effect #33

Open xigua88-66 opened 3 weeks ago

xigua88-66 commented 3 weeks ago

When I generated the pre-signed URL, I set an expiration time, but the link expiration time did not take effect, and the expiration time in the link was incorrect.

go version: 1.22 github.com/huaweicloud/huaweicloud-sdk-go-obs v3.24.9+incompatible

`func SignDownUrl(path string) { client, err := NewHuaWeiObsClient() if err != nil { fmt.Println(err) } expires := 60 input := obs.CreateSignedUrlInput{ Bucket: "migrate-to-minio-test", Key: path, Method: obs.HttpMethodGet, Expires: expires, }

signedUrl, err := client.CreateSignedUrl(&input)
if err != nil {
    fmt.Println(err)
}
fmt.Println(signedUrl.SignedUrl)

} ` The generated link is like: http://migrate-to-minio-test.obs.cn-north-4.myhuaweicloud.com:80/hudi-release-0.12.0.tar.gz?AWSAccessKeyId=GR6MO2GUCFAVCI&Expires=1730200189&Signature=G6czdPuWyvFoVsHerIYkLNw4TkM%3D

liqiuqiu111 commented 1 week ago

endPoint := "https://obs.cn-north-4.myhuaweicloud.com" // 创建obsClient实例 // 如果使用临时AKSK和SecurityToken访问OBS,需要在创建实例时通过obs.WithSecurityToken方法指定securityToken值。 obsClient, err := obs.New(ak, sk, endPoint/, obs.WithSecurityToken(securityToken)/) if err != nil { fmt.Printf("Create obsClient error, errMsg: %s", err.Error()) } putObjectInput := &obs.CreateSignedUrlInput{} putObjectInput.Method = obs.HttpMethodPut putObjectInput.Bucket = "examplebucket" putObjectInput.Key = "example/objectname" putObjectInput.Expires = 3600 // 生成上传对象的带授权信息的URL putObjectOutput, err := obsClient.CreateSignedUrl(putObjectInput) if err != nil { fmt.Println(err) return } fmt.Printf("SignedUrl:%s\n", putObjectOutput.SignedUrl) fmt.Printf("ActualSignedRequestHeaders:%v\n", putObjectOutput.ActualSignedRequestHeaders)

请按照官网demo,链接里的expires是通过服务器编译后的10位时间戳。