Skip to content

Commit

Permalink
Merge pull request #119 from 563750789/master
Browse files Browse the repository at this point in the history
更新万象接口
  • Loading branch information
563750789 authored Aug 2, 2022
2 parents 39e76a5 + 3db281f commit 89fa99d
Show file tree
Hide file tree
Showing 22 changed files with 798 additions and 100 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.6.99]
- update CI image processing API

## [5.6.97]
- update Auditing API

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.qcloud</groupId>
<artifactId>cos_api</artifactId>
<version>5.6.98</version>
<version>5.6.99</version>
<packaging>jar</packaging>
<name>cos-java-sdk</name>
<description>java sdk for qcloud cos</description>
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/qcloud/cos/COS.java
Original file line number Diff line number Diff line change
Expand Up @@ -3052,6 +3052,14 @@ SelectObjectContentResult selectObjectContent(SelectObjectContentRequest selectR
MediaWorkflowListResponse triggerWorkflowList(MediaWorkflowListRequest request);

InputStream getSnapshot(CosSnapshotRequest request);

String generateQrcode(GenerateQrcodeRequest request);

Boolean addImageStyle(ImageStyleRequest request);

ImageStyleResponse getImageStyle(ImageStyleRequest request);

Boolean deleteImageStyle(ImageStyleRequest request);
}


62 changes: 61 additions & 1 deletion src/main/java/com/qcloud/cos/COSClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.qcloud.cos.auth.COSSessionCredentials;
import com.qcloud.cos.auth.COSSigner;
import com.qcloud.cos.auth.COSStaticCredentialsProvider;
import com.qcloud.cos.endpoint.CIPicRegionEndpointBuilder;
import com.qcloud.cos.endpoint.CIRegionEndpointBuilder;
import com.qcloud.cos.endpoint.EndpointBuilder;
import com.qcloud.cos.endpoint.RegionEndpointBuilder;
Expand All @@ -64,6 +65,7 @@
import com.qcloud.cos.http.HttpResponseHandler;
import com.qcloud.cos.internal.BucketNameUtils;
import com.qcloud.cos.internal.CIGetSnapshotResponseHandler;
import com.qcloud.cos.internal.CIPicServiceRequest;
import com.qcloud.cos.internal.CIServiceRequest;
import com.qcloud.cos.internal.CIWorkflowServiceRequest;
import com.qcloud.cos.internal.COSDefaultAclHeaderHandler;
Expand Down Expand Up @@ -107,12 +109,15 @@
import com.qcloud.cos.model.ciModel.bucket.MediaBucketResponse;
import com.qcloud.cos.model.ciModel.common.ImageProcessRequest;
import com.qcloud.cos.model.ciModel.common.MediaOutputObject;
import com.qcloud.cos.model.ciModel.image.GenerateQrcodeRequest;
import com.qcloud.cos.model.ciModel.image.ImageLabelRequest;
import com.qcloud.cos.model.ciModel.image.ImageLabelResponse;
import com.qcloud.cos.model.ciModel.image.ImageLabelV2Request;
import com.qcloud.cos.model.ciModel.image.ImageLabelV2Response;
import com.qcloud.cos.model.ciModel.image.ImageSearchRequest;
import com.qcloud.cos.model.ciModel.image.ImageSearchResponse;
import com.qcloud.cos.model.ciModel.image.ImageStyleRequest;
import com.qcloud.cos.model.ciModel.image.ImageStyleResponse;
import com.qcloud.cos.model.ciModel.image.OpenImageSearchRequest;
import com.qcloud.cos.model.ciModel.job.DocHtmlRequest;
import com.qcloud.cos.model.ciModel.job.DocJobListRequest;
Expand Down Expand Up @@ -526,6 +531,8 @@ private <X extends CosServiceRequest> void buildUrlAndHost(CosHttpRequest<X> req
bucket = formatBucket(bucket, fetchCredential().getCOSAppId());
if (isCIRequest) {
endpoint = new CIRegionEndpointBuilder(clientConfig.getRegion()).buildGeneralApiEndpoint(bucket);
} else if (request.getOriginalRequest() instanceof CIPicServiceRequest) {
endpoint = new CIPicRegionEndpointBuilder(clientConfig.getRegion()).buildGeneralApiEndpoint(bucket);
} else {
endpoint = clientConfig.getEndpointBuilder().buildGeneralApiEndpoint(bucket);
}
Expand Down Expand Up @@ -4234,7 +4241,7 @@ public PutAsyncFetchTaskResult putAsyncFetchTask(PutAsyncFetchTaskRequest putAsy
CosHttpRequest<PutAsyncFetchTaskRequest> request = createRequest(putAsyncFetchTaskRequest.getBucketName(),
String.format("/%s/", putAsyncFetchTaskRequest.getBucketName()), putAsyncFetchTaskRequest, HttpMethodName.POST);
PutAsyncFetchTaskSerializer serializer = new PutAsyncFetchTaskSerializer(PutAsyncFetchTaskRequest.class);
SimpleModule module =
SimpleModule module =
new SimpleModule("PutAsyncFetchTaskSerializer", new Version(1, 0, 0, null, null, null));
module.addSerializer(PutAsyncFetchTaskRequest.class, serializer);

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

@Override
public String generateQrcode(GenerateQrcodeRequest generateQrcodeRequest) {
rejectNull(generateQrcodeRequest,
"The request parameter must be specified setting the object tags");
rejectNull(generateQrcodeRequest.getBucketName(),
"The bucketName parameter must be specified setting the object tags");
CosHttpRequest<GenerateQrcodeRequest> request = this.createRequest(generateQrcodeRequest.getBucketName(), "/", generateQrcodeRequest, HttpMethodName.GET);
addParameterIfNotNull(request, "ci-process", "qrcode-generate");
addParameterIfNotNull(request, "qrcode-content", generateQrcodeRequest.getQrcodeContent());
addParameterIfNotNull(request, "mode", generateQrcodeRequest.getMode());
addParameterIfNotNull(request, "width", generateQrcodeRequest.getWidth());
return this.invoke(request, new Unmarshallers.GenerateQrcodeUnmarshaller());
}

@Override
public Boolean addImageStyle(ImageStyleRequest imageStyleRequest) {
rejectNull(imageStyleRequest,
"The request parameter must be specified setting the object tags");
rejectNull(imageStyleRequest.getBucketName(),
"The bucketName parameter must be specified setting the object tags");
CosHttpRequest<ImageStyleRequest> request = createRequest(imageStyleRequest.getBucketName(), "/", imageStyleRequest, HttpMethodName.PUT);
request.addParameter("style", "");
this.setContent(request, CImageXmlFactory.addStyleConvertToXmlByteArray(imageStyleRequest), "application/xml", false);
invoke(request, voidCosResponseHandler);
return true;
}

@Override
public ImageStyleResponse getImageStyle(ImageStyleRequest imageStyleRequest) {
rejectNull(imageStyleRequest,
"The request parameter must be specified setting the object tags");
rejectNull(imageStyleRequest.getBucketName(),
"The bucketName parameter must be specified setting the object tags");
CosHttpRequest<ImageStyleRequest> request = createRequest(imageStyleRequest.getBucketName(), "/", imageStyleRequest, HttpMethodName.GET);
request.addParameter("style", "");
this.setContent(request, CImageXmlFactory.getStyleConvertToXmlByteArray(imageStyleRequest), "application/xml", false);
invoke(request, new Unmarshallers.getImageStyleUnmarshaller());
return null;
}

@Override
public Boolean deleteImageStyle(ImageStyleRequest imageStyleRequest) {
rejectNull(imageStyleRequest,
"The request parameter must be specified setting the object tags");
rejectNull(imageStyleRequest.getBucketName(),
"The bucketName parameter must be specified setting the object tags");
CosHttpRequest<ImageStyleRequest> request = createRequest(imageStyleRequest.getBucketName(), "/", imageStyleRequest, HttpMethodName.DELETE);
request.addParameter("style", "");
this.setContent(request, CImageXmlFactory.deleteStyleConvertToXmlByteArray(imageStyleRequest), "application/xml", false);
invoke(request, voidCosResponseHandler);
return true;
}

}

72 changes: 72 additions & 0 deletions src/main/java/com/qcloud/cos/demo/ci/ImageStyleDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.qcloud.cos.demo.ci;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.model.ciModel.image.ImageStyleRequest;
import com.qcloud.cos.model.ciModel.image.ImageStyleResponse;
import com.qcloud.cos.model.ciModel.image.StyleRule;

import java.util.List;


/**
* 图片样式接口 demo
* 接口详情见 https://cloud.tencent.com/document/product/460/30118
*/
public class ImageStyleDemo {
public static void main(String[] args) throws Exception {
COSClient cosClient = ClientUtils.getTestClient();
// 小于5GB文件用简单上传
addImageStyle(cosClient);
cosClient.shutdown();
}

/**
* 添加图片处理样式
* https://cloud.tencent.com/document/product/460/53491
*/
public static void addImageStyle(COSClient cosClient) {
//1.创建二维码生成请求对象
ImageStyleRequest request = new ImageStyleRequest();
//2.添加请求参数 参数详情请见api接口文档
request.setBucketName("examplebucket-1250000000");
request.setStyleName("DemoStyle");
//设置样式规则,demo此处处理规则含义为:缩放图片宽高为原图50%
request.setStyleBody("imageMogr2/thumbnail/!50p");
Boolean response = cosClient.addImageStyle(request);
}

/**
* 查询图片处理样式
* https://cloud.tencent.com/document/product/460/30117
*/
public static void getImageStyle(COSClient cosClient) {
//1.创建二维码生成请求对象
ImageStyleRequest request = new ImageStyleRequest();
//2.添加请求参数 参数详情请见api接口文档
request.setBucketName("examplebucket-1250000000");
request.setStyleName("DemoStyle");
ImageStyleResponse response = cosClient.getImageStyle(request);
List<StyleRule> styleRule = response.getStyleRule();
for (StyleRule rule : styleRule) {
System.out.println(rule.getStyleName());
System.out.println(rule.getStyleBody());
}
}

/**
* 查询图片处理样式
* https://cloud.tencent.com/document/product/460/30117
*/
public static void deleteImageStyle(COSClient cosClient) {
//1.创建二维码生成请求对象
ImageStyleRequest request = new ImageStyleRequest();
//2.添加请求参数 参数详情请见api接口文档
request.setBucketName("examplebucket-1250000000");
request.setStyleName("DemoStyle");
//设置样式规则,demo此处处理规则含义为:缩放图片宽高为原图50%
request.setStyleBody("imageMogr2/thumbnail/!50p");
Boolean response = cosClient.deleteImageStyle(request);
}


}
26 changes: 22 additions & 4 deletions src/main/java/com/qcloud/cos/demo/ci/QRCodeDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.qcloud.cos.model.UploadPartRequest;
import com.qcloud.cos.model.UploadPartResult;
import com.qcloud.cos.model.UploadResult;
import com.qcloud.cos.model.ciModel.image.GenerateQrcodeRequest;
import com.qcloud.cos.model.ciModel.persistence.CIObject;
import com.qcloud.cos.model.ciModel.persistence.CIUploadResult;
import com.qcloud.cos.model.ciModel.persistence.PicOperations;
Expand All @@ -27,6 +28,22 @@


public class QRCodeDemo {

/**
* 二维码生成 https://cloud.tencent.com/document/product/460/53491
*/
public static void generateQrcode(COSClient cosClient) {
//1.创建二维码生成请求对象
GenerateQrcodeRequest request = new GenerateQrcodeRequest();
//2.添加请求参数 参数详情请见api接口文档
request.setBucketName("examplebucket-1250000000");
request.setQrcodeContent("数据万象");
request.setWidth("400");
request.setMode("0");
String imageBase64 = cosClient.generateQrcode(request);
System.out.println(imageBase64);
}

public static void identifyQrCode(COSClient cosClient) {
// bucket名需包含appid
// api 请参考 https://cloud.tencent.com/document/product/436/54070
Expand All @@ -50,7 +67,7 @@ public static void identifyQrCode(COSClient cosClient) {
CIUploadResult ciUploadResult = putObjectResult.getCiUploadResult();
System.out.println(putObjectResult.getRequestId());
System.out.println(ciUploadResult.getOriginalInfo().getEtag());
for(CIObject ciObject:ciUploadResult.getProcessResults().getObjectList()) {
for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
System.out.println(ciObject.getLocation());
}
} catch (CosServiceException e) {
Expand Down Expand Up @@ -107,7 +124,7 @@ public static void identifyQrCodeWithMultipart(COSClient cosClient) throws FileN
CIUploadResult ciUploadResult = completeMultipartUploadResult.getCiUploadResult();
System.out.println(completeMultipartUploadResult.getRequestId());
System.out.println(ciUploadResult.getOriginalInfo().getEtag());
for(CIObject ciObject:ciUploadResult.getProcessResults().getObjectList()) {
for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
System.out.println(ciObject.getLocation());
}

Expand Down Expand Up @@ -136,14 +153,15 @@ public static void identifyQrCodeWithTransferManager(TransferManager transferMan
CIUploadResult ciUploadResult = uploadResult.getCiUploadResult();
System.out.println(uploadResult.getRequestId());
System.out.println(ciUploadResult.getOriginalInfo().getEtag());
for(CIObject ciObject:ciUploadResult.getProcessResults().getObjectList()) {
for (CIObject ciObject : ciUploadResult.getProcessResults().getObjectList()) {
System.out.println(ciObject.getLocation());
}
}

public static void main(String[] args) throws Exception {
COSClient cosClient = ClientUtils.getTestClient();
// 小于5GB文件用简单上传
identifyQrCode(cosClient);
generateQrcode(cosClient);
cosClient.shutdown();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
* According to cos feature, we modify some class,comment, field name, etc.
*/


package com.qcloud.cos.endpoint;

import com.qcloud.cos.internal.BucketNameUtils;
import com.qcloud.cos.region.Region;

public class CIPicRegionEndpointBuilder implements EndpointBuilder {
private Region region;

public CIPicRegionEndpointBuilder(Region region) {
super();
this.region = region;
}

@Override
public String buildGeneralApiEndpoint(String bucketName) {
if (this.region == null) {
throw new IllegalArgumentException("region is null");
}
BucketNameUtils.validateBucketName(bucketName);
return String.format("%s.pic.%s.myqcloud.com", bucketName, Region.formatCIRegion(this.region));
}

@Override
public String buildGetServiceApiEndpoint() {
return "service.pic.myqcloud.com";
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/qcloud/cos/internal/CIPicServiceRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2020 腾讯云, Inc. or its affiliates. All Rights Reserved.
*
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
* According to ci feature, we modify some class,comment, field name, etc.
*/

package com.qcloud.cos.internal;

public class CIPicServiceRequest extends CIServiceRequest {

}
Loading

0 comments on commit 89fa99d

Please sign in to comment.