Skip to content

Commit b385760

Browse files
author
wjielai
committed
增加用例
1 parent 2062327 commit b385760

File tree

4 files changed

+146
-12
lines changed

4 files changed

+146
-12
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.tencent.qcloud.cosxml.cssg;
2+
3+
import com.tencent.cos.xml.*;
4+
import com.tencent.cos.xml.common.*;
5+
import com.tencent.cos.xml.exception.*;
6+
import com.tencent.cos.xml.listener.*;
7+
import com.tencent.cos.xml.model.*;
8+
import com.tencent.cos.xml.model.object.*;
9+
import com.tencent.cos.xml.model.bucket.*;
10+
import com.tencent.cos.xml.model.tag.*;
11+
import com.tencent.cos.xml.transfer.*;
12+
import com.tencent.qcloud.core.auth.*;
13+
import com.tencent.qcloud.core.common.*;
14+
import com.tencent.qcloud.core.http.*;
15+
import com.tencent.cos.xml.model.service.*;
16+
import com.tencent.qcloud.cosxml.cssg.BuildConfig;
17+
18+
import android.content.Context;
19+
import android.util.Log;
20+
import android.support.test.InstrumentationRegistry;
21+
22+
import org.junit.Test;
23+
24+
import java.net.*;
25+
import java.util.*;
26+
import java.nio.charset.Charset;
27+
import java.io.*;
28+
29+
public class PictureOperation {
30+
31+
private Context context;
32+
private CosXmlService cosXmlService;
33+
34+
public static class ServerCredentialProvider extends BasicLifecycleCredentialProvider {
35+
36+
@Override
37+
protected QCloudLifecycleCredentials fetchNewCredentials() throws QCloudClientException {
38+
39+
// 首先从您的临时密钥服务器获取包含了密钥信息的响应
40+
41+
// 然后解析响应,获取密钥信息
42+
String tmpSecretId = "临时密钥 secretId";
43+
String tmpSecretKey = "临时密钥 secretKey";
44+
String sessionToken = "临时密钥 TOKEN";
45+
long expiredTime = 1556183496L;//临时密钥有效截止时间戳,单位是秒
46+
47+
/*强烈建议返回服务器时间作为签名的开始时间,用来避免由于用户手机本地时间偏差过大导致的签名不正确 */
48+
// 返回服务器时间作为签名的起始时间
49+
long startTime = 1556182000L; //临时密钥有效起始时间,单位是秒
50+
51+
// 最后返回临时密钥信息对象
52+
return new SessionQCloudCredentials(tmpSecretId, tmpSecretKey, sessionToken, startTime, expiredTime);
53+
}
54+
}
55+
56+
/**
57+
* 上传时图片处理
58+
*/
59+
private void uploadWithPicOperation() {
60+
//.cssg-snippet-body-start:[upload-with-pic-operation]
61+
62+
//.cssg-snippet-body-end
63+
}
64+
65+
// .cssg-methods-pragma
66+
67+
private void initService() {
68+
String region = "ap-guangzhou";
69+
70+
CosXmlServiceConfig serviceConfig = new CosXmlServiceConfig.Builder()
71+
.setRegion(region)
72+
.isHttps(true) // 使用 HTTPS 请求,默认为 HTTP 请求
73+
.builder();
74+
75+
context = InstrumentationRegistry.getInstrumentation().getTargetContext();
76+
cosXmlService = new CosXmlService(context, serviceConfig, new ServerCredentialProvider());
77+
}
78+
79+
@Test
80+
public void testPictureOperation() {
81+
initService();
82+
83+
// 上传时图片处理
84+
uploadWithPicOperation();
85+
86+
// .cssg-methods-pragma
87+
}
88+
}

Demo/app/src/androidTest/java/com/tencent/qcloud/cosxml/cssg/SetCustomDomain.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ private void setCustomDomain() {
8080
//.cssg-snippet-body-end
8181
}
8282

83+
/**
84+
* 设置全球加速域名
85+
*/
86+
private void setAccelerateDomain() {
87+
//.cssg-snippet-body-start:[set-accelerate-domain]
88+
89+
//.cssg-snippet-body-end
90+
}
91+
92+
8393
// .cssg-methods-pragma
8494

8595
private void initService() {
@@ -106,6 +116,10 @@ public void testSetCustomDomain() {
106116

107117
// 设置自定义域名
108118
setCustomDomain();
119+
120+
// 设置全球加速域名
121+
setAccelerateDomain();
122+
109123

110124
// .cssg-methods-pragma
111125
}

Demo/app/src/androidTest/java/com/tencent/qcloud/cosxml/cssg/TransferDownloadObject.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,19 @@ public void onStateChanged(TransferState state) {
117117
}
118118

119119
/**
120-
* 下载暂停与续传
120+
* 下载暂停、续传与取消
121121
*/
122-
private void transferDownloadObjectPauseAndResume() {
123-
//.cssg-snippet-body-start:[transfer-download-object-pause-and-resume]
124-
122+
private void transferDownloadObjectInteract() {
123+
//.cssg-snippet-body-start:[transfer-download-object-pause]
124+
125+
//.cssg-snippet-body-end
126+
127+
//.cssg-snippet-body-start:[transfer-download-object-resume]
128+
129+
//.cssg-snippet-body-end
130+
131+
//.cssg-snippet-body-start:[transfer-download-object-cancel]
132+
125133
//.cssg-snippet-body-end
126134
}
127135

@@ -134,6 +142,7 @@ private void transferBatchDownloadObjects() {
134142
//.cssg-snippet-body-end
135143
}
136144

145+
137146
// .cssg-methods-pragma
138147

139148
private void initService() {
@@ -155,12 +164,13 @@ public void testTransferDownloadObject() {
155164
// 高级接口下载对象
156165
transferDownloadObject();
157166

158-
// 下载暂停与续传
159-
transferDownloadObjectPauseAndResume();
167+
// 下载暂停、续传与取消
168+
transferDownloadObjectInteract();
160169

161170
// 批量下载
162171
transferBatchDownloadObjects();
163172

173+
164174
// .cssg-methods-pragma
165175
}
166176
}

Demo/app/src/androidTest/java/com/tencent/qcloud/cosxml/cssg/TransferUploadObject.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,28 @@ public void onFail(CosXmlRequest request,
192192
}
193193

194194
/**
195-
* 上传暂停与续传
195+
* 高级接口 URI 上传
196196
*/
197-
private void transferUploadPauseAndResume() {
198-
//.cssg-snippet-body-start:[transfer-upload-pause-and-resume]
199-
197+
private void transferUploadUri() {
198+
//.cssg-snippet-body-start:[transfer-upload-uri]
199+
200+
//.cssg-snippet-body-end
201+
}
202+
203+
/**
204+
* 上传暂停、续传与取消
205+
*/
206+
private void transferUploadInteract() {
207+
//.cssg-snippet-body-start:[transfer-upload-pause]
208+
209+
//.cssg-snippet-body-end
210+
211+
//.cssg-snippet-body-start:[transfer-upload-resume]
212+
213+
//.cssg-snippet-body-end
214+
215+
//.cssg-snippet-body-start:[transfer-upload-cancel]
216+
200217
//.cssg-snippet-body-end
201218
}
202219

@@ -209,6 +226,7 @@ private void transferBatchUploadObjects() {
209226
//.cssg-snippet-body-end
210227
}
211228

229+
212230
// .cssg-methods-pragma
213231

214232
private void initService() {
@@ -235,13 +253,17 @@ public void testTransferUploadObject() {
235253

236254
// 高级接口流式上传
237255
transferUploadStream();
256+
257+
// 高级接口 URI 上传
258+
transferUploadUri();
238259

239-
// 上传暂停与续传
240-
transferUploadPauseAndResume();
260+
// 上传暂停、续传与取消
261+
transferUploadInteract();
241262

242263
// 批量上传
243264
transferBatchUploadObjects();
244265

266+
245267
// .cssg-methods-pragma
246268
}
247269
}

0 commit comments

Comments
 (0)