简介
本文档提供关于图片样式的 API 概览以及 SDK 示例代码。
增加样式
功能说明
该接口用于对某一个存储桶设置样式功能,设置样式后,可以方便地对图片进行统一的处理。
方法原型
func (s *CIService) AddStyle(ctx context.Context, opt *AddStyleOptions) (*Response, error)
请求示例
style := &cos.AddStyleOptions{StyleName: "grayscale_1",StyleBody: "imageMogr2/grayscale/1",}_, err := c.CI.AddStyle(context.Background(), style)
参数说明
type AddStyleOptions struct {XMLName xml.Name `xml:"AddStyle"`StyleName string `xml:"StyleName,omitempty"`StyleBody string `xml:"StyleBody,omitempty"`}
参数名称 | 参数描述 | 类型 | 是否必填 |
StyleName | 样式名称 | string | 是 |
StyleBody | 样式详情 | string | 是 |
查询样式
功能说明
用于查询该 Bucket 下已有的样式。若不使用请求体,则查询该 Bucket 下的全部样式,若使用请求体,则查询请求体中携带的样式名信息。
方法原型
func (s *CIService) GetStyle(ctx context.Context, opt *GetStyleOptions) (*GetStyleResult, *Response, error)
请求示例
// 查询某个样式opt := &cos.GetStyleOptions{StyleName: "rotate_90"}res, _, err := c.CI.GetStyle(context.Background(), opt)// 查询所有样式res, _, err = c.CI.GetStyle(context.Background(), nil)
参数说明
type GetStyleOptions struct {XMLName xml.Name `xml:"GetStyle"`StyleName string `xml:"StyleName,omitempty"`}type GetStyleResult struct {XMLName xml.Name `xml:"StyleList"`StyleRule []StyleRule `xml:"StyleRule,omitempty"`}type StyleRule struct {StyleName string `xml:"StyleName,omitempty"`StyleBody string `xml:"StyleBody,omitempty"`}
删除样式
功能说明
用于删除某一特定样式。
方法原型
func (s *CIService) DeleteStyle(ctx context.Context, opt *DeleteStyleOptions) (*Response, error)
请求示例
style := &cos.DeleteStyleOptions{StyleName: "grayscale_1",}_, err := c.CI.DeleteStyle(context.Background(), style)
参数说明
type DeleteStyleOptions struct {XMLName xml.Name `xml:"DeleteStyle"`StyleName string `xml:"StyleName,omitempty"`}
参数名称 | 参数描述 | 类型 | 是否必填 |
StyleName | 样式名称 | string | 是 |