生成带授权信息的URL
更新时间: 2019-03-13 10:19
功能说明
通过访问密钥、请求方法类型、请求参数等信息生成一个在Query参数中携带鉴权信息的URL,以对OBS服务进行特定操作。
方法定义
- func (obsClient ObsClient) CreateSignedUrl(input *CreateSignedUrlInput) (output *CreateSignedUrlOutput, err error)
请求参数
参数名 | 类型 | 约束 |
---|---|---|
input | *CreateSignedUrlInput | 必选 |
返回结果
参数名 | 类型 |
---|---|
output | *CreateSignedUrlOutput |
err | error |
代码样例
- func main() {
- // 生成上传对象的带授权信息的URL
- putObjectInput := &obs.CreateSignedUrlInput{}
- putObjectInput.Method = obs.HttpMethodPut
- putObjectInput.Bucket = "bucketname"
- putObjectInput.Key = "objectkey"
- putObjectInput.Expires = 3600
- putObjectOutput, err := obsClient.CreateSignedUrl(putObjectInput)
- if err == nil {
- fmt.Printf("SignedUrl:%s\n", putObjectOutput.SignedUrl)
- fmt.Printf("ActualSignedRequestHeaders:%v\n", putObjectOutput.ActualSignedRequestHeaders)
- } else {
- fmt.Println(err)
- }
- // 生成下载对象的带授权信息的URL
- getObjectInput := &obs.CreateSignedUrlInput{}
- getObjectInput.Method = obs.HttpMethodGet
- getObjectInput.Bucket = "bucketname"
- getObjectInput.Key = "objectkey"
- getObjectInput.Expires = 3600
- getObjectOutput, err := obsClient.CreateSignedUrl(getObjectInput)
- if err == nil {
- fmt.Printf("SignedUrl:%s\n", getObjectOutput.SignedUrl)
- fmt.Printf("ActualSignedRequestHeaders:%v\n", getObjectOutput.ActualSignedRequestHeaders)
- } else {
- fmt.Println(err)
- }
- // 生成删除对象的带授权信息的URL
- deleteObjectInput := &obs.CreateSignedUrlInput{}
- deleteObjectInput.Method = obs.HttpMethodDelete
- deleteObjectInput.Bucket = "bucketname"
- deleteObjectInput.Key = "objectkey"
- deleteObjectInput.Expires = 3600
- deleteObjectOutput, err := obsClient.CreateSignedUrl(deleteObjectInput)
- if err == nil {
- fmt.Printf("SignedUrl:%s\n", deleteObjectOutput.SignedUrl)
- fmt.Printf("ActualSignedRequestHeaders:%v\n", deleteObjectOutput.ActualSignedRequestHeaders)
- } else {
- fmt.Println(err)
- }
- }
父主题:其他接口