Skip to content

Commit e620a04

Browse files
author
Joshua Yin
committed
* 兼容性修复ObjectListWithDirFormatApi中,若后台返回UserMeta=null导致异常的bug
1 parent e9a5239 commit e620a04

File tree

13 files changed

+39
-34
lines changed

13 files changed

+39
-34
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.2</version>
28+
<version>2.4.3</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.2'
39+
implementation 'cn.ucloud.ufile:ufile-client-java:2.4.3'
4040
}
4141
```
4242

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public class Constants {
4343
* 请修改下面的公私钥
4444
*/
4545
public static final ObjectAuthorization OBJECT_AUTHORIZER = new UfileObjectLocalAuthorization(
46-
"UcloudPublicKey",
47-
"UcloudPrivateKey");
46+
System.getenv("UcloudPublicKey"),
47+
System.getenv("UcloudPrivateKey"));
4848

4949
/**
5050
* 远程Object相关API的签名器

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public class GetObjectSample {
3333
private static ObjectConfig config = new ObjectConfig("cn-sh2", "ufileos.com");
3434

3535
public static void main(String[] args) {
36-
String keyName = "";
37-
String bucketName = "";
36+
String keyName = "jdk-8u192-macosx-x64.dmg";
37+
String bucketName = "new-bucket";
3838
// 5 * 60秒 --> 5分钟后过期
3939
int expiresDuration = 5 * 60;
4040

41-
String localDir = "";
42-
String saveName = "";
41+
String localDir = "/Users/joshua/MyResource/FileDetachTest/ftp";
42+
String saveName = keyName;
4343
try {
4444
String url = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
4545
.getDownloadUrlFromPrivateBucket(keyName, bucketName, expiresDuration)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ObjectListWithDirFormatSample {
2828
private static ObjectConfig config = new ObjectConfig("cn-sh2", "ufileos.com");
2929

3030
public static void main(String[] args) {
31-
String bucketName = "";
31+
String bucketName = "new-bucket";
3232

3333
execute_list_all(bucketName);
3434
}
@@ -94,6 +94,8 @@ public static void execute_list_all(String bucketName) {
9494
if (response == null || response.getObjectContents() == null)
9595
break;
9696

97+
JLog.D(TAG, "[response-demo]:" + response.toString());
98+
9799
for (ObjectContentBean content : response.getObjectContents()) {
98100
if (content == null)
99101
continue;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
*/
2828
public class PutObjectSample {
2929
private static final String TAG = "PutObjectSample";
30-
private static ObjectConfig config = new ObjectConfig("cn-sh2", "ufileos.com");
30+
private static ObjectConfig config = new ObjectConfig("cn-bj", "ufileos.com");
3131

3232
public static void main(String[] args) {
3333
InputStream is = new ByteArrayInputStream(new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07});
3434
// 如果上传File,则文件的MimeType可以使用MimeTypeUtil.getMimeType(File)来获取,MimeTypeUtil可能支持的type类型不全,用户可以按需自行填写
35-
File file = new File("");
36-
String keyName = "";
35+
File file = new File("/Users/joshua/Downloads/test.jpg");
36+
String keyName = file.getName();
3737
String mimeType = MimeTypeUtil.getMimeType(keyName);
38-
String bucketName = "";
39-
putStream(is, mimeType, keyName, bucketName);
38+
String bucketName = "test-bkt";
39+
putFile(file, mimeType, keyName, bucketName);
4040
}
4141

4242
public static void putFile(File file, String mimeType, String nameAs, String toBucket) {

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.2</version>
10+
<version>2.4.3</version>
1111

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

ufile/ufile-client-java/apidocs.zip

20.7 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.2</version>
9+
<version>2.4.3</version>
1010
</parent>
1111

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

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,20 @@ public ObjectListWithDirFormatBean parseHttpResponse(Response response) throws U
196196
if (content == null || content.getJsonUserMeta() == null)
197197
continue;
198198

199-
JsonObject json = content.getJsonUserMeta();
200-
Set<String> keys = json.keySet();
201-
if (keys != null) {
202-
Map<String, String> metadata = new HashMap<>();
203-
for (String name : keys) {
204-
if (name == null || name.isEmpty())
205-
continue;
206-
207-
metadata.put(name.toLowerCase(), json.get(name).getAsString());
199+
JsonElement json = content.getJsonUserMeta();
200+
if (json != null && json instanceof JsonObject) {
201+
JsonObject jsonObj= (JsonObject) json;
202+
Set<String> keys = jsonObj.keySet();
203+
if (keys != null) {
204+
Map<String, String> metadata = new HashMap<>();
205+
for (String name : keys) {
206+
if (name == null || name.isEmpty())
207+
continue;
208+
209+
metadata.put(name.toLowerCase(), jsonObj.get(name).getAsString());
210+
}
211+
content.setUserMeta(metadata);
208212
}
209-
content.setUserMeta(metadata);
210213
}
211214
}
212215
}

ufile/ufile-client-java/src/main/java/cn/ucloud/ufile/bean/ObjectContentBean.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cn.ucloud.ufile.bean;
22

33
import com.google.gson.Gson;
4-
import com.google.gson.JsonObject;
4+
import com.google.gson.JsonElement;
55
import com.google.gson.annotations.SerializedName;
66

77
import java.io.Serializable;
@@ -30,7 +30,7 @@ public class ObjectContentBean implements Serializable {
3030
@SerializedName("CreateTime")
3131
private Long createTime;
3232
@SerializedName("UserMeta")
33-
private JsonObject jsonUserMeta;
33+
private JsonElement jsonUserMeta;
3434
private transient Map<String, String> userMeta;
3535

3636
public String getBucketName() {
@@ -97,7 +97,7 @@ public void setCreateTime(long createTime) {
9797
this.createTime = createTime;
9898
}
9999

100-
public JsonObject getJsonUserMeta() {
100+
public JsonElement getJsonUserMeta() {
101101
return jsonUserMeta;
102102
}
103103

ufile/ufile-core/apidocs.zip

-221 Bytes
Binary file not shown.

ufile/ufile-core/pom.xml

Lines changed: 2 additions & 2 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.2</version>
9+
<version>2.4.3</version>
1010
</parent>
1111

1212
<artifactId>ufile-core</artifactId>
13-
<version>2.4.2</version>
13+
<version>2.4.3</version>
1414

1515
<dependencies>
1616
<dependency>

ufile/ufile-core/src/main/java/cn/ucloud/ufile/UfileConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @date: 2018/11/22 15:00
77
*/
88
public class UfileConstants {
9-
public static final String SDK_VERSION = "2.4.2";
9+
public static final String SDK_VERSION = "2.4.3";
1010
/**
1111
* 默认分片大小(4MB)
1212
*/

0 commit comments

Comments
 (0)