Skip to content

Commit 23dae5f

Browse files
author
Joshua Yin
committed
* 修复遗漏bug隐患
* 新增putFile/Stream和getDownloadUrlFromPublic/PrivateBucket的iopcmd参数,支持图像处理
1 parent 6de4d7a commit 23dae5f

20 files changed

Lines changed: 166 additions & 33 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<dependency>
2626
<groupId>cn.ucloud.ufile</groupId>
2727
<artifactId>ufile-client-java</artifactId>
28-
<version>2.4.4</version>
28+
<version>2.5.0</version>
2929
</dependency>
3030
```
3131

@@ -36,7 +36,7 @@
3636
/*
3737
* your other dependencies
3838
*/
39-
implementation 'cn.ucloud.ufile:ufile-client-java:2.4.4'
39+
implementation 'cn.ucloud.ufile:ufile-client-java:2.5.0'
4040
}
4141
```
4242

ufile-sample-java/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>cn.ucloud.ufile</groupId>
2828
<artifactId>ufile-client-java</artifactId>
29-
<version>2.4.4</version>
29+
<version>2.5.0</version>
3030
</dependency>
3131
</dependencies>
3232

ufile-sample-java/src/main/java/cn/ucloud/ufile/sample/object/DownloadFileSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static void downloadFile(String keyName, String bucketName, String localD
4646
.downloadFile(profile)
4747
.saveAt(localDir, saveName)
4848
/**
49-
* 选择要下载的对象的范围,Default = (0, whole size)
49+
* 选择要下载的对象的范围,Default = [0, whole size]
5050
*/
5151
// .withinRange(0, 0)
5252
/**

ufile-sample-java/src/main/java/cn/ucloud/ufile/sample/object/GetObjectSample.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ public class GetObjectSample {
3535
public static void main(String[] args) {
3636
String keyName = "";
3737
String bucketName = "";
38+
String localDir = "";
39+
String saveName = "";
40+
3841
// 5 * 60秒 --> 5分钟后过期
3942
int expiresDuration = 5 * 60;
4043

41-
String localDir = "";
42-
String saveName = "";
4344
try {
4445
String url = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
4546
.getDownloadUrlFromPrivateBucket(keyName, bucketName, expiresDuration)
@@ -51,6 +52,11 @@ public static void main(String[] args) {
5152
* 使用Content-Disposition: attachment,并且配置文件名
5253
*/
5354
// .withAttachment("filename")
55+
/**
56+
* 图片处理服务
57+
* https://docs.ucloud.cn/ufile/service/pic
58+
*/
59+
// .withIopCmd("iopcmd=rotate&degree=90")
5460
.createUrl();
5561
getStream(url, localDir, saveName);
5662
} catch (UfileParamException e) {
@@ -69,6 +75,10 @@ public static void getFile(String url, String localDir, String saveName) {
6975
DownloadFileBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
7076
.getFile(url)
7177
.saveAt(localDir, saveName)
78+
/**
79+
* 选择要下载的对象的范围,Default = [0, whole size]
80+
*/
81+
// .withinRange(0, 0)
7282
/**
7383
* 是否覆盖本地已有文件, Default = true;
7484
*/
@@ -103,6 +113,10 @@ public static void getFileAsync(String url, String localDir, String saveName) {
103113
UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
104114
.getFile(url)
105115
.saveAt(localDir, saveName)
116+
/**
117+
* 选择要下载的对象的范围,Default = [0, whole size]
118+
*/
119+
// .withinRange(0, 0)
106120
/**
107121
* 是否覆盖本地已有文件, Default = true;
108122
*/
@@ -142,6 +156,10 @@ public static void getStream(String url, String localDir, String saveName) {
142156

143157
DownloadStreamBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
144158
.getStream(url)
159+
/**
160+
* 选择要下载的对象的范围,Default = [0, whole size]
161+
*/
162+
// .withinRange(0, 0)
145163
/**
146164
* 重定向流
147165
*
@@ -189,6 +207,10 @@ public static void getStreamAsync(String url, String localDir, String saveName)
189207

190208
UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
191209
.getStream(url)
210+
/**
211+
* 选择要下载的对象的范围,Default = [0, whole size]
212+
*/
213+
// .withinRange(0, 0)
192214
/**
193215
* 重定向流
194216
*

ufile-sample-java/src/main/java/cn/ucloud/ufile/sample/object/PutObjectSample.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public static void main(String[] args) {
3434
// 如果上传File,则文件的MimeType可以使用MimeTypeUtil.getMimeType(File)来获取,MimeTypeUtil可能支持的type类型不全,用户可以按需自行填写
3535
File file = new File("");
3636
String keyName = "";
37-
String mimeType = MimeTypeUtil.getMimeType(keyName);
3837
String bucketName = "";
38+
String mimeType = MimeTypeUtil.getMimeType(keyName);
3939
putStream(is, mimeType, keyName, bucketName);
4040
}
4141

@@ -57,6 +57,11 @@ public static void putFile(File file, String mimeType, String nameAs, String toB
5757
* 配置文件存储类型,分别是标准、低频、冷存,对应有效值:STANDARD | IA | ARCHIVE
5858
*/
5959
.withStorageType(StorageType.STANDARD)
60+
/**
61+
* 图片处理服务
62+
* https://docs.ucloud.cn/ufile/service/pic
63+
*/
64+
// .withIopCmd("iopcmd=rotate&degree=90")
6065
/**
6166
* 为云端对象配置自定义数据,每次调用将会替换之前数据。
6267
* 所有的自定义数据总大小不能超过 8KB。
@@ -119,6 +124,11 @@ public static void putFileAsync(File file, String mimeType, String nameAs, Strin
119124
* 配置文件存储类型,分别是标准、低频、冷存,对应有效值:STANDARD | IA | ARCHIVE
120125
*/
121126
.withStorageType(StorageType.STANDARD)
127+
/**
128+
* 图片处理服务
129+
* https://docs.ucloud.cn/ufile/service/pic
130+
*/
131+
// .withIopCmd("iopcmd=rotate&degree=90")
122132
/**
123133
* 为云端对象配置自定义数据,每次调用将会替换之前数据。
124134
* 所有的自定义数据总大小不能超过 8KB。
@@ -184,6 +194,11 @@ public static void putStream(InputStream stream, String mimeType, String nameAs,
184194
* 配置文件存储类型,分别是标准、低频、冷存,对应有效值:STANDARD | IA | ARCHIVE
185195
*/
186196
.withStorageType(StorageType.STANDARD)
197+
/**
198+
* 图片处理服务
199+
* https://docs.ucloud.cn/ufile/service/pic
200+
*/
201+
// .withIopCmd("iopcmd=rotate&degree=90")
187202
/**
188203
* 为云端对象配置自定义数据,每次调用将会替换之前数据。
189204
* 所有的自定义数据总大小不能超过 8KB。
@@ -246,6 +261,11 @@ public static void putStreamAsync(InputStream stream, String mimeType, String na
246261
* 配置文件存储类型,分别是标准、低频、冷存,对应有效值:STANDARD | IA | ARCHIVE
247262
*/
248263
.withStorageType(StorageType.STANDARD)
264+
/**
265+
* 图片处理服务
266+
* https://docs.ucloud.cn/ufile/service/pic
267+
*/
268+
// .withIopCmd("iopcmd=rotate&degree=90")
249269
/**
250270
* 为云端对象配置自定义数据,每次调用将会替换之前数据。
251271
* 所有的自定义数据总大小不能超过 8KB。

ufile/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>cn.ucloud.ufile</groupId>
88
<artifactId>ufile</artifactId>
99
<packaging>pom</packaging>
10-
<version>2.4.4</version>
10+
<version>2.5.0</version>
1111

1212
<modules>
1313
<module>ufile-core</module>
954 Bytes
Binary file not shown.

ufile/ufile-client-java/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<parent>
77
<artifactId>ufile</artifactId>
88
<groupId>cn.ucloud.ufile</groupId>
9-
<version>2.4.4</version>
9+
<version>2.5.0</version>
1010
</parent>
1111

1212
<artifactId>ufile-client-java</artifactId>
13-
<version>2.4.4</version>
13+
<version>2.5.0</version>
1414

1515
<dependencies>
1616
<dependency>
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>cn.ucloud.ufile</groupId>
2828
<artifactId>ufile-core</artifactId>
29-
<version>2.4.4</version>
29+
<version>2.5.0</version>
3030
</dependency>
3131
</dependencies>
3232

ufile/ufile-client-java/src/main/java/cn/ucloud/ufile/api/object/DownloadFileApi.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public DownloadFileApi which(ObjectProfile profile) {
153153
}
154154

155155
/**
156-
* 选择要下载的对象的范围,Default = (0, whole size)
156+
* 选择要下载的对象的范围,Default = [0, whole size]
157157
*
158158
* @param start range起点
159159
* @param end range终点
@@ -509,11 +509,8 @@ public DownloadFileBean call() throws Exception {
509509
if (response == null)
510510
throw new UfileHttpException("Response is null");
511511

512-
if (response.code() != RESP_CODE_SUCCESS) {
513-
if (response.code() / 100 != 2)
514-
throw new UfileHttpException(parseErrorResponse(response).toString());
515-
throw new UfileHttpException(String.format("Response code = %d, need %d", response.code(), RESP_CODE_SUCCESS));
516-
}
512+
if (response.code() / 100 != 2)
513+
throw new UfileHttpException(parseErrorResponse(response).toString());
517514

518515
DownloadFileBean result = parseHttpResponse(response);
519516
if (index == 0 || index == (partCount - 1)) {

ufile/ufile-client-java/src/main/java/cn/ucloud/ufile/api/object/GenerateObjectPrivateUrlApi.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.io.UnsupportedEncodingException;
1616
import java.net.URLEncoder;
17+
import java.util.List;
1718

1819

1920
/**
@@ -53,6 +54,11 @@ public class GenerateObjectPrivateUrlApi {
5354
*/
5455
private JsonElement authOptionalData;
5556

57+
/**
58+
* 图片处理服务
59+
*/
60+
protected String iopCmd;
61+
5662
/**
5763
* 构造方法
5864
*
@@ -92,6 +98,17 @@ public GenerateObjectPrivateUrlApi withAttachment() {
9298
return this;
9399
}
94100

101+
/**
102+
* 针对图片文件的操作参数
103+
*
104+
* @param iopCmd 请参考 https://docs.ucloud.cn/ufile/service/pic
105+
* @return {@link GenerateObjectPrivateUrlApi}
106+
*/
107+
public GenerateObjectPrivateUrlApi withIopCmd(String iopCmd) {
108+
this.iopCmd = iopCmd;
109+
return this;
110+
}
111+
95112

96113
/**
97114
* 配置签名可选参数
@@ -137,7 +154,17 @@ public String createUrl() throws UfileClientException {
137154
}
138155

139156

140-
return builder.generateGetUrl(builder.getBaseUrl(), builder.getParams());
157+
String url = builder.generateGetUrl(builder.getBaseUrl(), builder.getParams());
158+
if (iopCmd != null && !iopCmd.isEmpty()) {
159+
List<Parameter<String>> params = builder.getParams();
160+
if (params == null || params.isEmpty()) {
161+
url = String.format("%s?%s", url, iopCmd);
162+
} else {
163+
url = String.format("%s&%s", url, iopCmd);
164+
}
165+
}
166+
167+
return url;
141168
}
142169

143170
public interface CreatePrivateUrlCallback {

0 commit comments

Comments
 (0)