查看PDF

生成带授权信息的URL

更新时间: 2019-03-13 10:19

功能说明

通过访问密钥、请求方法类型、请求参数等信息生成一个在Query参数中携带鉴权信息的URL,以对OBS服务进行特定操作。

方法定义

  1. func (obsClient ObsClient) CreateSignedUrl(input *CreateSignedUrlInput) (output *CreateSignedUrlOutput, err error)

请求参数


参数名

类型

约束

input

*CreateSignedUrlInput

必选

返回结果


参数名

类型

output

*CreateSignedUrlOutput

err

error

代码样例

  1. func main() {
  2. // 生成上传对象的带授权信息的URL
  3. putObjectInput := &obs.CreateSignedUrlInput{}
  4. putObjectInput.Method = obs.HttpMethodPut
  5. putObjectInput.Bucket = "bucketname"
  6. putObjectInput.Key = "objectkey"
  7. putObjectInput.Expires = 3600
  8. putObjectOutput, err := obsClient.CreateSignedUrl(putObjectInput)
  9. if err == nil {
  10. fmt.Printf("SignedUrl:%s\n", putObjectOutput.SignedUrl)
  11. fmt.Printf("ActualSignedRequestHeaders:%v\n", putObjectOutput.ActualSignedRequestHeaders)
  12. } else {
  13. fmt.Println(err)
  14. }
  15.  
  16. // 生成下载对象的带授权信息URL
  17. getObjectInput := &obs.CreateSignedUrlInput{}
  18. getObjectInput.Method = obs.HttpMethodGet
  19. getObjectInput.Bucket = "bucketname"
  20. getObjectInput.Key = "objectkey"
  21. getObjectInput.Expires = 3600
  22. getObjectOutput, err := obsClient.CreateSignedUrl(getObjectInput)
  23. if err == nil {
  24. fmt.Printf("SignedUrl:%s\n", getObjectOutput.SignedUrl)
  25. fmt.Printf("ActualSignedRequestHeaders:%v\n", getObjectOutput.ActualSignedRequestHeaders)
  26. } else {
  27. fmt.Println(err)
  28. }
  29.  
  30. // 生成删除对象的带授权信息的URL
  31. deleteObjectInput := &obs.CreateSignedUrlInput{}
  32. deleteObjectInput.Method = obs.HttpMethodDelete
  33. deleteObjectInput.Bucket = "bucketname"
  34. deleteObjectInput.Key = "objectkey"
  35. deleteObjectInput.Expires = 3600
  36. deleteObjectOutput, err := obsClient.CreateSignedUrl(deleteObjectInput)
  37. if err == nil {
  38. fmt.Printf("SignedUrl:%s\n", deleteObjectOutput.SignedUrl)
  39. fmt.Printf("ActualSignedRequestHeaders:%v\n", deleteObjectOutput.ActualSignedRequestHeaders)
  40. } else {
  41. fmt.Println(err)
  42. }
  43. }

父主题:其他接口