Skip to content

Commit fd3421c

Browse files
author
joshua.yin
authored
Merge pull request #37 from JoshuaYin/master
2.4.2
2 parents fadd08a + e9a5239 commit fd3421c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+270
-197
lines changed

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.1</version>
28+
<version>2.4.2</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.1'
39+
implementation 'cn.ucloud.ufile:ufile-client-java:2.4.2'
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.1</version>
29+
<version>2.4.2</version>
3030
</dependency>
3131
</dependencies>
3232

ufile-sample-java/src/main/java/cn/ucloud/ufile/sample/Constants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import cn.ucloud.ufile.UfileClient;
44
import cn.ucloud.ufile.auth.*;
55
import cn.ucloud.ufile.http.HttpClient;
6-
import cn.ucloud.ufile.http.interceptor.LogInterceptor;
76
import cn.ucloud.ufile.util.JLog;
87

98
import java.util.concurrent.Executors;

ufile-sample-java/src/main/java/cn/ucloud/ufile/sample/object/multi/MultiUploadSample.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import cn.ucloud.ufile.api.object.policy.PutPolicyForCallback;
1010
import cn.ucloud.ufile.bean.MultiUploadResponse;
1111
import cn.ucloud.ufile.bean.base.BaseObjectResponseBean;
12-
import cn.ucloud.ufile.bean.base.BaseResponseBean;
1312
import cn.ucloud.ufile.exception.UfileClientException;
1413
import cn.ucloud.ufile.exception.UfileServerException;
1514
import cn.ucloud.ufile.http.OnProgressListener;

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.1</version>
10+
<version>2.4.2</version>
1111

1212
<modules>
1313
<module>ufile-core</module>

ufile/ufile-client-java/apidocs.zip

-19.6 KB
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.1</version>
9+
<version>2.4.2</version>
1010
</parent>
1111

1212
<artifactId>ufile-client-java</artifactId>
13-
<version>2.4.1</version>
13+
<version>2.4.2</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.1</version>
29+
<version>2.4.2</version>
3030
</dependency>
3131
</dependencies>
3232

ufile/ufile-client-java/src/main/java/cn/ucloud/ufile/UfileClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,6 @@ public synchronized static BucketApiBuilder bucket(BucketAuthorizer authorizer)
142142
* @return Object相关API构造器 {@link ObjectApiBuilder}
143143
*/
144144
public synchronized static ObjectApiBuilder object(ObjectAuthorizer authorizer, ObjectConfig config) {
145-
return new ObjectApiBuilder(createClient(), authorizer, config.host());
145+
return new ObjectApiBuilder(createClient(), authorizer, config);
146146
}
147147
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ public class AppendObjectApi extends UfileObjectApi<AppendObjectResultBean> {
7474
/**
7575
* 构造方法
7676
*
77-
* @param authorizer Object授权器
78-
* @param host API域名
79-
* @param httpClient Http客户端
77+
* @param authorizer Object授权器
78+
* @param objectConfig ObjectConfig {@link ObjectConfig}
79+
* @param httpClient Http客户端
8080
*/
81-
protected AppendObjectApi(ObjectAuthorizer authorizer, String host, HttpClient httpClient) {
82-
super(authorizer, host, httpClient);
81+
protected AppendObjectApi(ObjectAuthorizer authorizer, ObjectConfig objectConfig, HttpClient httpClient) {
82+
super(authorizer, objectConfig, httpClient);
8383
progressConfig = ProgressConfig.callbackDefault();
8484
}
8585

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ public class CopyObjectApi extends UfileObjectApi<CopyObjectResultBean> {
6565
/**
6666
* 构造方法
6767
*
68-
* @param authorizer Object授权器
69-
* @param host API域名
70-
* @param httpClient Http客户端
68+
* @param authorizer Object授权器
69+
* @param objectConfig ObjectConfig {@link ObjectConfig}
70+
* @param httpClient Http客户端
7171
*/
72-
protected CopyObjectApi(ObjectAuthorizer authorizer, String host, HttpClient httpClient) {
73-
super(authorizer, host, httpClient);
72+
protected CopyObjectApi(ObjectAuthorizer authorizer, ObjectConfig objectConfig, HttpClient httpClient) {
73+
super(authorizer, objectConfig, httpClient);
7474
}
7575

7676
/**

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public class DeleteObjectApi extends UfileObjectApi<BaseObjectResponseBean> {
4141
/**
4242
* 构造方法
4343
*
44-
* @param authorizer Object授权器
45-
* @param host API域名
46-
* @param httpClient Http客户端
44+
* @param authorizer Object授权器
45+
* @param objectConfig ObjectConfig {@link ObjectConfig}
46+
* @param httpClient Http客户端
4747
*/
48-
protected DeleteObjectApi(ObjectAuthorizer authorizer, String host, HttpClient httpClient) {
49-
super(authorizer, host, httpClient);
48+
protected DeleteObjectApi(ObjectAuthorizer authorizer, ObjectConfig objectConfig, HttpClient httpClient) {
49+
super(authorizer, objectConfig, httpClient);
5050
RESP_CODE_SUCCESS = 204;
5151
}
5252

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ public class DownloadFileApi extends UfileObjectApi<DownloadFileBean> {
118118
/**
119119
* 构造方法
120120
*
121-
* @param authorizer Object授权器
122-
* @param host API域名
123-
* @param httpClient Http客户端
121+
* @param authorizer Object授权器
122+
* @param objectConfig ObjectConfig {@link ObjectConfig}
123+
* @param httpClient Http客户端
124124
*/
125-
protected DownloadFileApi(ObjectAuthorizer authorizer, String host, HttpClient httpClient) {
126-
super(authorizer, host, httpClient);
125+
protected DownloadFileApi(ObjectAuthorizer authorizer, ObjectConfig objectConfig, HttpClient httpClient) {
126+
super(authorizer, objectConfig, httpClient);
127127
RESP_CODE_SUCCESS = 206;
128128
progressConfig = ProgressConfig.callbackDefault();
129129
}
@@ -256,7 +256,7 @@ protected void prepareData() throws UfileClientException {
256256
rangeEnd = profile.getContentLength() - 1;
257257
totalSize = rangeEnd - rangeStart + 1;
258258

259-
host = new GenerateObjectPrivateUrlApi(authorizer, host, profile.getKeyName(), profile.getBucket(), expiresDuration)
259+
host = new GenerateObjectPrivateUrlApi(authorizer, objectConfig, profile.getKeyName(), profile.getBucket(), expiresDuration)
260260
.withAuthOptionalData(authOptionalData)
261261
.createUrl();
262262

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
public class GenerateObjectPrivateUrlApi {
2727
private ObjectAuthorizer authorizer;
28-
private String host;
28+
private ObjectConfig objectConfig;
2929

3030
/**
3131
* Required
@@ -57,21 +57,23 @@ public class GenerateObjectPrivateUrlApi {
5757
* 构造方法
5858
*
5959
* @param authorizer Object授权器
60-
* @param host API域名
60+
* @param objectConfig ObjectConfig {@link ObjectConfig}
6161
* @param keyName 对象名称
6262
* @param bucketName bucket名称
6363
* @param expiresDuration 私有下载路径的有效时间,即:生成的下载URL会在 创建时刻的时间戳 + expiresDuration毫秒 后的时刻过期
6464
*/
65-
protected GenerateObjectPrivateUrlApi(ObjectAuthorizer authorizer, String host, String keyName, String bucketName, int expiresDuration) {
65+
protected GenerateObjectPrivateUrlApi(ObjectAuthorizer authorizer, ObjectConfig objectConfig,
66+
String keyName, String bucketName, int expiresDuration) {
6667
this.authorizer = authorizer;
67-
this.host = host;
68+
this.objectConfig = objectConfig;
6869
this.keyName = keyName;
6970
this.bucketName = bucketName;
7071
this.expiresDuration = expiresDuration;
7172
}
7273

7374
/**
7475
* 使用Content-Disposition: attachment,并配置attachment的文件名
76+
*
7577
* @param attachmentFileName Content-Disposition: attachment的文件名
7678
* @return
7779
*/
@@ -82,6 +84,7 @@ public GenerateObjectPrivateUrlApi withAttachment(String attachmentFileName) {
8284

8385
/**
8486
* 使用Content-Disposition: attachment,并且文件名默认为keyName
87+
*
8588
* @return
8689
*/
8790
public GenerateObjectPrivateUrlApi withAttachment() {
@@ -169,18 +172,23 @@ public void run() {
169172
}
170173

171174
private String generateFinalHost(String bucketName, String keyName) throws UfileClientException {
172-
if (host == null || host.length() == 0)
173-
return host;
175+
if (objectConfig == null)
176+
return null;
174177

175-
if (host.startsWith("http"))
176-
return String.format("%s/%s", host, keyName);
178+
if (objectConfig.isCustomDomain())
179+
return String.format("%s/%s", objectConfig.getCustomHost(), keyName);
177180

178181
try {
179182
bucketName = URLEncoder.encode(bucketName, "UTF-8").replace("+", "%20");
183+
String region = URLEncoder.encode(objectConfig.getRegion(), "UTF-8")
184+
.replace("+", "%20");
185+
String proxySuffix = URLEncoder.encode(objectConfig.getProxySuffix(), "UTF-8")
186+
.replace("+", "%20");
180187
keyName = URLEncoder.encode(keyName, "UTF-8").replace("+", "%20");
181-
return String.format("http://%s.%s/%s", bucketName, host, keyName);
188+
return new StringBuilder(objectConfig.getProtocol().getValue())
189+
.append(String.format("%s.%s.%s/%s", bucketName, region, proxySuffix, keyName)).toString();
182190
} catch (UnsupportedEncodingException e) {
183-
throw new UfileClientException("Occur error during URLEncode bucketName and keyName");
191+
throw new UfileClientException("Occur error during URLEncode bucketName and keyName", e);
184192
}
185193
}
186194

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* @date: 2018/11/16 12:00
1818
*/
1919
public class GenerateObjectPublicUrlApi {
20-
private String host;
20+
private ObjectConfig objectConfig;
2121
/**
2222
* Required
2323
* 云端对象名称
@@ -37,18 +37,19 @@ public class GenerateObjectPublicUrlApi {
3737
/**
3838
* 构造方法
3939
*
40-
* @param host API域名
41-
* @param keyName 对象名称
42-
* @param bucketName bucket名称
40+
* @param objectConfig ObjectConfig {@link ObjectConfig}
41+
* @param keyName 对象名称
42+
* @param bucketName bucket名称
4343
*/
44-
protected GenerateObjectPublicUrlApi(String host, String keyName, String bucketName) {
45-
this.host = host;
44+
protected GenerateObjectPublicUrlApi(ObjectConfig objectConfig, String keyName, String bucketName) {
45+
this.objectConfig = objectConfig;
4646
this.keyName = keyName;
4747
this.bucketName = bucketName;
4848
}
4949

5050
/**
5151
* 使用Content-Disposition: attachment,并配置attachment的文件名
52+
*
5253
* @param attachmentFileName Content-Disposition: attachment的文件名
5354
* @return
5455
*/
@@ -59,6 +60,7 @@ public GenerateObjectPublicUrlApi withAttachment(String attachmentFileName) {
5960

6061
/**
6162
* 使用Content-Disposition: attachment,并且文件名默认为keyName
63+
*
6264
* @return
6365
*/
6466
public GenerateObjectPublicUrlApi withAttachment() {
@@ -90,18 +92,23 @@ public String createUrl() throws UfileClientException {
9092
}
9193

9294
private String generateFinalHost(String bucketName, String keyName) throws UfileClientException {
93-
if (host == null || host.length() == 0)
94-
return host;
95+
if (objectConfig == null)
96+
return null;
9597

96-
if (host.startsWith("http"))
97-
return String.format("%s/%s", host, keyName);
98+
if (objectConfig.isCustomDomain())
99+
return String.format("%s/%s", objectConfig.getCustomHost(), keyName);
98100

99101
try {
100-
bucketName = URLEncoder.encode(bucketName, "UTF-8").replace("+","%20");
101-
keyName = URLEncoder.encode(keyName, "UTF-8").replace("+","%20");
102-
return String.format("http://%s.%s/%s", bucketName, host, keyName);
102+
bucketName = URLEncoder.encode(bucketName, "UTF-8").replace("+", "%20");
103+
String region = URLEncoder.encode(objectConfig.getRegion(), "UTF-8")
104+
.replace("+", "%20");
105+
String proxySuffix = URLEncoder.encode(objectConfig.getProxySuffix(), "UTF-8")
106+
.replace("+", "%20");
107+
keyName = URLEncoder.encode(keyName, "UTF-8").replace("+", "%20");
108+
return new StringBuilder(objectConfig.getProtocol().getValue())
109+
.append(String.format("%s.%s.%s/%s", bucketName, region, proxySuffix, keyName)).toString();
103110
} catch (UnsupportedEncodingException e) {
104-
throw new UfileClientException("Occur error during URLEncode bucketName and keyName");
111+
throw new UfileClientException("Occur error during URLEncode bucketName and keyName", e);
105112
}
106113
}
107114

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ public class GetFileApi extends UfileObjectApi<DownloadFileBean> {
6666
/**
6767
* 构造方法
6868
*
69-
* @param authorizer Object授权器
70-
* @param host API域名
71-
* @param httpClient Http客户端
69+
* @param authorizer Object授权器
70+
* @param objectConfig ObjectConfig {@link ObjectConfig}
71+
* @param httpClient Http客户端
7272
*/
73-
protected GetFileApi(ObjectAuthorizer authorizer, String host, HttpClient httpClient) {
74-
super(authorizer, host, httpClient);
73+
protected GetFileApi(ObjectAuthorizer authorizer, ObjectConfig objectConfig, HttpClient httpClient) {
74+
super(authorizer, objectConfig, httpClient);
7575
RESP_CODE_SUCCESS = 206;
76+
host = objectConfig.getCustomHost();
7677
progressConfig = ProgressConfig.callbackDefault();
7778
}
7879

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ public class GetStreamApi extends UfileObjectApi<DownloadStreamBean> {
5454
/**
5555
* 构造方法
5656
*
57-
* @param authorizer Object授权器
58-
* @param host API域名
59-
* @param httpClient Http客户端
57+
* @param authorizer Object授权器
58+
* @param objectConfig ObjectConfig {@link ObjectConfig}
59+
* @param httpClient Http客户端
6060
*/
61-
protected GetStreamApi(ObjectAuthorizer authorizer, String host, HttpClient httpClient) {
62-
super(authorizer, host, httpClient);
61+
protected GetStreamApi(ObjectAuthorizer authorizer, ObjectConfig objectConfig, HttpClient httpClient) {
62+
super(authorizer, objectConfig, httpClient);
6363
RESP_CODE_SUCCESS = 206;
64+
host = objectConfig.getCustomHost();
6465
progressConfig = ProgressConfig.callbackDefault();
6566
}
6667

0 commit comments

Comments
 (0)