Skip to content

Commit d4cc963

Browse files
author
wanjiewu
committed
支持云上处理能力设置自定义header
1 parent 0f16ea4 commit d4cc963

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

ci.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,25 @@ func (s *CIService) ImageProcess(ctx context.Context, name string, opt *ImagePro
110110
return &res, resp, err
111111
}
112112

113+
type ImageProcessHeader struct {
114+
PicOperations string `header:"Pic-Operations" xml:"-" url:"-"`
115+
XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"`
116+
}
117+
118+
// 云上数据处理 https://cloud.tencent.com/document/product/460/18147
119+
func (s *CIService) ImageProcessWithHeader(ctx context.Context, name string, opt *ImageProcessHeader) (*ImageProcessResult, *Response, error) {
120+
var res ImageProcessResult
121+
sendOpt := sendOptions{
122+
baseURL: s.client.BaseURL.BucketURL,
123+
uri: "/" + encodeURIComponent(name) + "?image_process",
124+
method: http.MethodPost,
125+
optHeader: opt,
126+
result: &res,
127+
}
128+
resp, err := s.client.send(ctx, &sendOpt)
129+
return &res, resp, err
130+
}
131+
113132
// ImageRecognitionOptions is the option of ImageAuditing
114133
type ImageRecognitionOptions struct {
115134
CIProcess string `url:"ci-process,omitempty"`

example/CI/image_process/base_process.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,29 @@ func processWhenCloud(ctx context.Context, rawurl, obj string, pic *cos.PicOpera
137137
fmt.Printf("%+v\n", res.ProcessResults)
138138
}
139139

140+
// 云上数据处理
141+
func processWhenCloudWithHeader(ctx context.Context, rawurl, obj string, imageProcessHeader *cos.ImageProcessHeader ) {
142+
u, _ := url.Parse(rawurl)
143+
b := &cos.BaseURL{BucketURL: u}
144+
c := cos.NewClient(b, &http.Client{
145+
Transport: &cos.AuthorizationTransport{
146+
SecretID: os.Getenv("COS_SECRETID"),
147+
SecretKey: os.Getenv("COS_SECRETKEY"),
148+
Transport: &debug.DebugRequestTransport{
149+
RequestHeader: true,
150+
RequestBody: false,
151+
ResponseHeader: true,
152+
ResponseBody: true,
153+
},
154+
},
155+
})
156+
res, _, err := c.CI.ImageProcessWithHeader(ctx, obj, imageProcessHeader)
157+
log_status(err)
158+
fmt.Printf("%+v\n", res)
159+
fmt.Printf("%+v\n", res.OriginalInfo)
160+
fmt.Printf("%+v\n", res.ProcessResults)
161+
}
162+
140163
// 添加盲水印
141164
func blindWatermark() {
142165
rawurl := "https://test-1234567890.cos.ap-chongqing.myqcloud.com"
@@ -1097,6 +1120,7 @@ func textWatermarkAndAIGC() {
10971120
}
10981121
processWhenUpload(context.Background(), rawurl, obj, filepath, pic)
10991122
}
1123+
11001124
// 云上数据处理
11011125
{
11021126
obj := "pic/deer.jpeg"
@@ -1111,6 +1135,27 @@ func textWatermarkAndAIGC() {
11111135
}
11121136
processWhenCloud(context.Background(), rawurl, obj, pic)
11131137
}
1138+
1139+
// 云上数据处理
1140+
{
1141+
obj := "pic/deer.jpeg"
1142+
pic := &cos.PicOperations{
1143+
IsPicInfo: 1,
1144+
Rules: []cos.PicOperationsRules{
1145+
{
1146+
FileId: "textwatermark/textwatermark1.jpg",
1147+
Rule: "imageMogr2/" + AIGCMetadata + "|watermark/2/text/6IW-6K6v5LqRwrfkuIfosaHkvJjlm74/fill/IzNEM0QzRA/fontsize/20/dissolve/50/gravity/northeast/dx/20/dy/20/batch/1/degree/45",
1148+
},
1149+
},
1150+
}
1151+
imageProcessHeader := &cos.ImageProcessHeader{
1152+
PicOperations: cos.EncodePicOperations(pic),
1153+
XOptionHeader: &http.Header{},
1154+
}
1155+
imageProcessHeader.XOptionHeader.Add("x-cos-meta-aigctag", "csig")
1156+
processWhenCloudWithHeader(context.Background(), rawurl, obj, imageProcessHeader)
1157+
}
1158+
11141159
}
11151160

11161161
func main() {

0 commit comments

Comments
 (0)