Skip to content

Commit 89fa99d

Browse files
authored
Merge pull request #119 from 563750789/master
更新万象接口
2 parents 39e76a5 + 3db281f commit 89fa99d

22 files changed

+798
-100
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [5.6.99]
9+
- update CI image processing API
10+
811
## [5.6.97]
912
- update Auditing API
1013

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.qcloud</groupId>
66
<artifactId>cos_api</artifactId>
7-
<version>5.6.98</version>
7+
<version>5.6.99</version>
88
<packaging>jar</packaging>
99
<name>cos-java-sdk</name>
1010
<description>java sdk for qcloud cos</description>

src/main/java/com/qcloud/cos/COS.java

+8
Original file line numberDiff line numberDiff line change
@@ -3052,6 +3052,14 @@ SelectObjectContentResult selectObjectContent(SelectObjectContentRequest selectR
30523052
MediaWorkflowListResponse triggerWorkflowList(MediaWorkflowListRequest request);
30533053

30543054
InputStream getSnapshot(CosSnapshotRequest request);
3055+
3056+
String generateQrcode(GenerateQrcodeRequest request);
3057+
3058+
Boolean addImageStyle(ImageStyleRequest request);
3059+
3060+
ImageStyleResponse getImageStyle(ImageStyleRequest request);
3061+
3062+
Boolean deleteImageStyle(ImageStyleRequest request);
30553063
}
30563064

30573065

src/main/java/com/qcloud/cos/COSClient.java

+61-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.qcloud.cos.auth.COSSessionCredentials;
4949
import com.qcloud.cos.auth.COSSigner;
5050
import com.qcloud.cos.auth.COSStaticCredentialsProvider;
51+
import com.qcloud.cos.endpoint.CIPicRegionEndpointBuilder;
5152
import com.qcloud.cos.endpoint.CIRegionEndpointBuilder;
5253
import com.qcloud.cos.endpoint.EndpointBuilder;
5354
import com.qcloud.cos.endpoint.RegionEndpointBuilder;
@@ -64,6 +65,7 @@
6465
import com.qcloud.cos.http.HttpResponseHandler;
6566
import com.qcloud.cos.internal.BucketNameUtils;
6667
import com.qcloud.cos.internal.CIGetSnapshotResponseHandler;
68+
import com.qcloud.cos.internal.CIPicServiceRequest;
6769
import com.qcloud.cos.internal.CIServiceRequest;
6870
import com.qcloud.cos.internal.CIWorkflowServiceRequest;
6971
import com.qcloud.cos.internal.COSDefaultAclHeaderHandler;
@@ -107,12 +109,15 @@
107109
import com.qcloud.cos.model.ciModel.bucket.MediaBucketResponse;
108110
import com.qcloud.cos.model.ciModel.common.ImageProcessRequest;
109111
import com.qcloud.cos.model.ciModel.common.MediaOutputObject;
112+
import com.qcloud.cos.model.ciModel.image.GenerateQrcodeRequest;
110113
import com.qcloud.cos.model.ciModel.image.ImageLabelRequest;
111114
import com.qcloud.cos.model.ciModel.image.ImageLabelResponse;
112115
import com.qcloud.cos.model.ciModel.image.ImageLabelV2Request;
113116
import com.qcloud.cos.model.ciModel.image.ImageLabelV2Response;
114117
import com.qcloud.cos.model.ciModel.image.ImageSearchRequest;
115118
import com.qcloud.cos.model.ciModel.image.ImageSearchResponse;
119+
import com.qcloud.cos.model.ciModel.image.ImageStyleRequest;
120+
import com.qcloud.cos.model.ciModel.image.ImageStyleResponse;
116121
import com.qcloud.cos.model.ciModel.image.OpenImageSearchRequest;
117122
import com.qcloud.cos.model.ciModel.job.DocHtmlRequest;
118123
import com.qcloud.cos.model.ciModel.job.DocJobListRequest;
@@ -526,6 +531,8 @@ private <X extends CosServiceRequest> void buildUrlAndHost(CosHttpRequest<X> req
526531
bucket = formatBucket(bucket, fetchCredential().getCOSAppId());
527532
if (isCIRequest) {
528533
endpoint = new CIRegionEndpointBuilder(clientConfig.getRegion()).buildGeneralApiEndpoint(bucket);
534+
} else if (request.getOriginalRequest() instanceof CIPicServiceRequest) {
535+
endpoint = new CIPicRegionEndpointBuilder(clientConfig.getRegion()).buildGeneralApiEndpoint(bucket);
529536
} else {
530537
endpoint = clientConfig.getEndpointBuilder().buildGeneralApiEndpoint(bucket);
531538
}
@@ -4234,7 +4241,7 @@ public PutAsyncFetchTaskResult putAsyncFetchTask(PutAsyncFetchTaskRequest putAsy
42344241
CosHttpRequest<PutAsyncFetchTaskRequest> request = createRequest(putAsyncFetchTaskRequest.getBucketName(),
42354242
String.format("/%s/", putAsyncFetchTaskRequest.getBucketName()), putAsyncFetchTaskRequest, HttpMethodName.POST);
42364243
PutAsyncFetchTaskSerializer serializer = new PutAsyncFetchTaskSerializer(PutAsyncFetchTaskRequest.class);
4237-
SimpleModule module =
4244+
SimpleModule module =
42384245
new SimpleModule("PutAsyncFetchTaskSerializer", new Version(1, 0, 0, null, null, null));
42394246
module.addSerializer(PutAsyncFetchTaskRequest.class, serializer);
42404247

@@ -4379,5 +4386,58 @@ public InputStream getSnapshot(CosSnapshotRequest snapshotRequest) {
43794386
return this.invoke(request, new CIGetSnapshotResponseHandler());
43804387
}
43814388

4389+
@Override
4390+
public String generateQrcode(GenerateQrcodeRequest generateQrcodeRequest) {
4391+
rejectNull(generateQrcodeRequest,
4392+
"The request parameter must be specified setting the object tags");
4393+
rejectNull(generateQrcodeRequest.getBucketName(),
4394+
"The bucketName parameter must be specified setting the object tags");
4395+
CosHttpRequest<GenerateQrcodeRequest> request = this.createRequest(generateQrcodeRequest.getBucketName(), "/", generateQrcodeRequest, HttpMethodName.GET);
4396+
addParameterIfNotNull(request, "ci-process", "qrcode-generate");
4397+
addParameterIfNotNull(request, "qrcode-content", generateQrcodeRequest.getQrcodeContent());
4398+
addParameterIfNotNull(request, "mode", generateQrcodeRequest.getMode());
4399+
addParameterIfNotNull(request, "width", generateQrcodeRequest.getWidth());
4400+
return this.invoke(request, new Unmarshallers.GenerateQrcodeUnmarshaller());
4401+
}
4402+
4403+
@Override
4404+
public Boolean addImageStyle(ImageStyleRequest imageStyleRequest) {
4405+
rejectNull(imageStyleRequest,
4406+
"The request parameter must be specified setting the object tags");
4407+
rejectNull(imageStyleRequest.getBucketName(),
4408+
"The bucketName parameter must be specified setting the object tags");
4409+
CosHttpRequest<ImageStyleRequest> request = createRequest(imageStyleRequest.getBucketName(), "/", imageStyleRequest, HttpMethodName.PUT);
4410+
request.addParameter("style", "");
4411+
this.setContent(request, CImageXmlFactory.addStyleConvertToXmlByteArray(imageStyleRequest), "application/xml", false);
4412+
invoke(request, voidCosResponseHandler);
4413+
return true;
4414+
}
4415+
4416+
@Override
4417+
public ImageStyleResponse getImageStyle(ImageStyleRequest imageStyleRequest) {
4418+
rejectNull(imageStyleRequest,
4419+
"The request parameter must be specified setting the object tags");
4420+
rejectNull(imageStyleRequest.getBucketName(),
4421+
"The bucketName parameter must be specified setting the object tags");
4422+
CosHttpRequest<ImageStyleRequest> request = createRequest(imageStyleRequest.getBucketName(), "/", imageStyleRequest, HttpMethodName.GET);
4423+
request.addParameter("style", "");
4424+
this.setContent(request, CImageXmlFactory.getStyleConvertToXmlByteArray(imageStyleRequest), "application/xml", false);
4425+
invoke(request, new Unmarshallers.getImageStyleUnmarshaller());
4426+
return null;
4427+
}
4428+
4429+
@Override
4430+
public Boolean deleteImageStyle(ImageStyleRequest imageStyleRequest) {
4431+
rejectNull(imageStyleRequest,
4432+
"The request parameter must be specified setting the object tags");
4433+
rejectNull(imageStyleRequest.getBucketName(),
4434+
"The bucketName parameter must be specified setting the object tags");
4435+
CosHttpRequest<ImageStyleRequest> request = createRequest(imageStyleRequest.getBucketName(), "/", imageStyleRequest, HttpMethodName.DELETE);
4436+
request.addParameter("style", "");
4437+
this.setContent(request, CImageXmlFactory.deleteStyleConvertToXmlByteArray(imageStyleRequest), "application/xml", false);
4438+
invoke(request, voidCosResponseHandler);
4439+
return true;
4440+
}
4441+
43824442
}
43834443

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.qcloud.cos.demo.ci;
2+
3+
import com.qcloud.cos.COSClient;
4+
import com.qcloud.cos.model.ciModel.image.ImageStyleRequest;
5+
import com.qcloud.cos.model.ciModel.image.ImageStyleResponse;
6+
import com.qcloud.cos.model.ciModel.image.StyleRule;
7+
8+
import java.util.List;
9+
10+
11+
/**
12+
* 图片样式接口 demo
13+
* 接口详情见 https://cloud.tencent.com/document/product/460/30118
14+
*/
15+
public class ImageStyleDemo {
16+
public static void main(String[] args) throws Exception {
17+
COSClient cosClient = ClientUtils.getTestClient();
18+
// 小于5GB文件用简单上传
19+
addImageStyle(cosClient);
20+
cosClient.shutdown();
21+
}
22+
23+
/**
24+
* 添加图片处理样式
25+
* https://cloud.tencent.com/document/product/460/53491
26+
*/
27+
public static void addImageStyle(COSClient cosClient) {
28+
//1.创建二维码生成请求对象
29+
ImageStyleRequest request = new ImageStyleRequest();
30+
//2.添加请求参数 参数详情请见api接口文档
31+
request.setBucketName("examplebucket-1250000000");
32+
request.setStyleName("DemoStyle");
33+
//设置样式规则,demo此处处理规则含义为:缩放图片宽高为原图50%
34+
request.setStyleBody("imageMogr2/thumbnail/!50p");
35+
Boolean response = cosClient.addImageStyle(request);
36+
}
37+
38+
/**
39+
* 查询图片处理样式
40+
* https://cloud.tencent.com/document/product/460/30117
41+
*/
42+
public static void getImageStyle(COSClient cosClient) {
43+
//1.创建二维码生成请求对象
44+
ImageStyleRequest request = new ImageStyleRequest();
45+
//2.添加请求参数 参数详情请见api接口文档
46+
request.setBucketName("examplebucket-1250000000");
47+
request.setStyleName("DemoStyle");
48+
ImageStyleResponse response = cosClient.getImageStyle(request);
49+
List<StyleRule> styleRule = response.getStyleRule();
50+
for (StyleRule rule : styleRule) {
51+
System.out.println(rule.getStyleName());
52+
System.out.println(rule.getStyleBody());
53+
}
54+
}
55+
56+
/**
57+
* 查询图片处理样式
58+
* https://cloud.tencent.com/document/product/460/30117
59+
*/
60+
public static void deleteImageStyle(COSClient cosClient) {
61+
//1.创建二维码生成请求对象
62+
ImageStyleRequest request = new ImageStyleRequest();
63+
//2.添加请求参数 参数详情请见api接口文档
64+
request.setBucketName("examplebucket-1250000000");
65+
request.setStyleName("DemoStyle");
66+
//设置样式规则,demo此处处理规则含义为:缩放图片宽高为原图50%
67+
request.setStyleBody("imageMogr2/thumbnail/!50p");
68+
Boolean response = cosClient.deleteImageStyle(request);
69+
}
70+
71+
72+
}

src/main/java/com/qcloud/cos/demo/ci/QRCodeDemo.java

+22-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.qcloud.cos.model.UploadPartRequest;
1414
import com.qcloud.cos.model.UploadPartResult;
1515
import com.qcloud.cos.model.UploadResult;
16+
import com.qcloud.cos.model.ciModel.image.GenerateQrcodeRequest;
1617
import com.qcloud.cos.model.ciModel.persistence.CIObject;
1718
import com.qcloud.cos.model.ciModel.persistence.CIUploadResult;
1819
import com.qcloud.cos.model.ciModel.persistence.PicOperations;
@@ -27,6 +28,22 @@
2728

2829

2930
public class QRCodeDemo {
31+
32+
/**
33+
* 二维码生成 https://cloud.tencent.com/document/product/460/53491
34+
*/
35+
public static void generateQrcode(COSClient cosClient) {
36+
//1.创建二维码生成请求对象
37+
GenerateQrcodeRequest request = new GenerateQrcodeRequest();
38+
//2.添加请求参数 参数详情请见api接口文档
39+
request.setBucketName("examplebucket-1250000000");
40+
request.setQrcodeContent("数据万象");
41+
request.setWidth("400");
42+
request.setMode("0");
43+
String imageBase64 = cosClient.generateQrcode(request);
44+
System.out.println(imageBase64);
45+
}
46+
3047
public static void identifyQrCode(COSClient cosClient) {
3148
// bucket名需包含appid
3249
// api 请参考 https://cloud.tencent.com/document/product/436/54070
@@ -50,7 +67,7 @@ public static void identifyQrCode(COSClient cosClient) {
5067
CIUploadResult ciUploadResult = putObjectResult.getCiUploadResult();
5168
System.out.println(putObjectResult.getRequestId());
5269
System.out.println(ciUploadResult.getOriginalInfo().getEtag());
53-
for(CIObject ciObject:ciUploadResult.getProcessResults().getObjectList()) {
70+
for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
5471
System.out.println(ciObject.getLocation());
5572
}
5673
} catch (CosServiceException e) {
@@ -107,7 +124,7 @@ public static void identifyQrCodeWithMultipart(COSClient cosClient) throws FileN
107124
CIUploadResult ciUploadResult = completeMultipartUploadResult.getCiUploadResult();
108125
System.out.println(completeMultipartUploadResult.getRequestId());
109126
System.out.println(ciUploadResult.getOriginalInfo().getEtag());
110-
for(CIObject ciObject:ciUploadResult.getProcessResults().getObjectList()) {
127+
for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
111128
System.out.println(ciObject.getLocation());
112129
}
113130

@@ -136,14 +153,15 @@ public static void identifyQrCodeWithTransferManager(TransferManager transferMan
136153
CIUploadResult ciUploadResult = uploadResult.getCiUploadResult();
137154
System.out.println(uploadResult.getRequestId());
138155
System.out.println(ciUploadResult.getOriginalInfo().getEtag());
139-
for(CIObject ciObject:ciUploadResult.getProcessResults().getObjectList()) {
156+
for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
140157
System.out.println(ciObject.getLocation());
141158
}
142159
}
160+
143161
public static void main(String[] args) throws Exception {
144162
COSClient cosClient = ClientUtils.getTestClient();
145163
// 小于5GB文件用简单上传
146-
identifyQrCode(cosClient);
164+
generateQrcode(cosClient);
147165
cosClient.shutdown();
148166
}
149167
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
15+
* According to cos feature, we modify some class,comment, field name, etc.
16+
*/
17+
18+
19+
package com.qcloud.cos.endpoint;
20+
21+
import com.qcloud.cos.internal.BucketNameUtils;
22+
import com.qcloud.cos.region.Region;
23+
24+
public class CIPicRegionEndpointBuilder implements EndpointBuilder {
25+
private Region region;
26+
27+
public CIPicRegionEndpointBuilder(Region region) {
28+
super();
29+
this.region = region;
30+
}
31+
32+
@Override
33+
public String buildGeneralApiEndpoint(String bucketName) {
34+
if (this.region == null) {
35+
throw new IllegalArgumentException("region is null");
36+
}
37+
BucketNameUtils.validateBucketName(bucketName);
38+
return String.format("%s.pic.%s.myqcloud.com", bucketName, Region.formatCIRegion(this.region));
39+
}
40+
41+
@Override
42+
public String buildGetServiceApiEndpoint() {
43+
return "service.pic.myqcloud.com";
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2020 腾讯云, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License").
7+
* You may not use this file except in compliance with the License.
8+
* A copy of the License is located at
9+
*
10+
* http://aws.amazon.com/apache2.0
11+
*
12+
* or in the "license" file accompanying this file. This file is distributed
13+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
17+
* According to ci feature, we modify some class,comment, field name, etc.
18+
*/
19+
20+
package com.qcloud.cos.internal;
21+
22+
public class CIPicServiceRequest extends CIServiceRequest {
23+
24+
}

0 commit comments

Comments
 (0)