设置桶的CORS配置
更新时间: 2019-03-13 10:26
功能说明
设置桶的跨域资源共享规则,以允许客户端浏览器进行跨域请求。
方法定义
- func (obsClient ObsClient) SetBucketCors(input *SetBucketCorsInput) (output *BaseModel, err error)
使用带授权信息URL的方法定义
- func (obsClient ObsClient) SetBucketCorsWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error)
请求参数
参数名 | 类型 | 约束 |
---|---|---|
input | *SetBucketCorsInput | 必选 |
返回结果
参数名 | 类型 |
---|---|
output | *BaseModel |
err | error |
代码样例
- func main() {
- input := &obs.SetBucketCorsInput{}
- input.Bucket = "bucketname"
- var corsRules [2]obs.CorsRule
- corsRule0 := obs.CorsRule{}
- corsRule0.ID = "rule1"
- corsRule0.AllowedOrigin = []string{"http://www.a.com", "http://www.b.com"}
- corsRule0.AllowedMethod = []string{"GET", "PUT", "POST", "HEAD"}
- corsRule0.AllowedHeader = []string{"header1", "header2"}
- corsRule0.MaxAgeSeconds = 100
- corsRule0.ExposeHeader = []string{"obs-1", "obs-2"}
- corsRules[0] = corsRule0
- corsRule1 := obs.CorsRule{}
- corsRule1.ID = "rule2"
- corsRule1.AllowedOrigin = []string{"http://www.c.com", "http://www.d.com"}
- corsRule1.AllowedMethod = []string{"GET", "PUT", "POST", "HEAD"}
- corsRule1.AllowedHeader = []string{"header3", "header4"}
- corsRule1.MaxAgeSeconds = 50
- corsRule1.ExposeHeader = []string{"obs-3", "obs-4"}
- corsRules[1] = corsRule1
- input.CorsRules = corsRules[:]
- output, err := obsClient.SetBucketCors(input)
- if err == nil {
- fmt.Printf("RequestId:%s\n", output.RequestId)
- } else {
- if obsError, ok := err.(obs.ObsError); ok {
- fmt.Println(obsError.Code)
- fmt.Println(obsError.Message)
- } else {
- fmt.Println(err)
- }
- }
- }
父主题:桶相关接口