Skip to content

Commit b2345fd

Browse files
committed
update to 4.1.1
1 parent e402490 commit b2345fd

File tree

7 files changed

+92
-75
lines changed

7 files changed

+92
-75
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<dependency>
1111
<groupId>com.upyun</groupId>
1212
<artifactId>java-sdk</artifactId>
13-
<version>4.1.0</version>
13+
<version>4.1.1</version>
1414
</dependency>
1515
1616
```
@@ -21,7 +21,7 @@
2121

2222
## 目录
2323
* [云存储基础接口](#云存储基础接口)
24-
* [初始化 UpYun](#初始化 UpYun)
24+
* [初始化 UpYun](#初始化UpYun)
2525
* [创建目录](#创建目录)
2626
* [删除目录](#删除目录)
2727
* [获取目录文件列表](#获取目录文件列表)
@@ -37,7 +37,7 @@
3737
* [图片裁剪](#图片裁剪)
3838
* [图片旋转](#图片旋转)
3939
* [表单上传接口](#表单上传接口)
40-
* [初始化 FormUploader](#初始化 FormUploader)
40+
* [初始化 FormUploader](#初始化FormUploader)
4141
* [表单上传文件](#表单上传文件)
4242
* [表单上传作图](#表单上传作图)
4343
* [错误说明](#错误说明)
@@ -54,7 +54,7 @@
5454
<a name="云存储基础接口"></a>
5555
## 云存储基础接口
5656

57-
<a name="初始化 UpYun"></a>
57+
<a name="初始化UpYun"></a>
5858
### 初始化 UpYun
5959

6060
```Java
@@ -157,7 +157,7 @@ public boolean rmDir(String path);
157157
**方法原型:**
158158

159159
```Java
160-
public List<FolderItem> readDir(String path);
160+
public List<FolderItem> readDir(String path,Map<String, String> params);
161161
```
162162
>`UpYun.FolderItem` 包含属性:
163163
>
@@ -171,6 +171,7 @@ public List<FolderItem> readDir(String path);
171171
**参数说明:**
172172

173173
* `path` 目录路径
174+
* `params` 可选参数
174175

175176
**返回值说明:**
176177

@@ -182,7 +183,7 @@ public List<FolderItem> readDir(String path);
182183
```Java
183184
String path = "/dir1/";
184185
// 获取目录中文件列表
185-
List<UpYun.FolderItem> items = upyun.readDir(path);
186+
List<UpYun.FolderItem> items = upyun.readDir(path,null);
186187
for (int i = 0; i < items.size(); i++) {
187188
System.out.println(items.get(i));
188189
}
@@ -335,12 +336,13 @@ public Map<String, String> getFileInfo(String filePath);
335336
**方法原型:**
336337

337338
```Java
338-
public boolean deleteFile(String filePath);
339+
public boolean deleteFile(String filePath,Map<String, String> params);
339340
```
340341

341342
**参数说明:**
342343

343344
* `filePath` 文件在又拍云的路径
345+
* `params ` 可选参数 可为 null
344346

345347
**返回值说明:**
346348

@@ -352,7 +354,7 @@ public Map<String, String> getFileInfo(String filePath);
352354
```Java
353355
String filePath = "/path/to/file";
354356
// 删除文件
355-
boolean result = upyun.deleteFile(filePath);
357+
boolean result = upyun.deleteFile(filePath, null);
356358
```
357359

358360
<a name="串行式断点续传"></a>
@@ -539,7 +541,7 @@ public Map<String, String> getFileInfo(String filePath);
539541
<a name="表单上传接口"></a>
540542
## 表单上传接口
541543

542-
<a name="初始化 FormUploader"></a>
544+
<a name="初始化FormUploader"></a>
543545
### 初始化 FormUploader
544546

545547
```java

src/main/java/com/UpYun.java

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,12 @@ public Map<String, String> getFileInfo(String filePath) throws IOException, UpEx
532532
* 删除文件
533533
*
534534
* @param filePath 文件路径(包含文件名)
535+
* @param params 额外参数
535536
* @return true or false
536537
*/
537-
public boolean deleteFile(String filePath) throws IOException, UpException {
538+
public boolean deleteFile(String filePath, Map<String, String> params) throws IOException, UpException {
538539

539-
return HttpAction(METHOD_DELETE, formatPath(filePath)) != null;
540+
return HttpAction(METHOD_DELETE, formatPath(filePath), params) != null;
540541
}
541542

542543
/**
@@ -570,12 +571,13 @@ public boolean mkDir(String path, boolean auto) throws IOException, UpException
570571
/**
571572
* 读取目录列表
572573
*
573-
* @param path 目录路径
574+
* @param path 目录路径
575+
* @param params 分页参数
574576
* @return List<FolderItem> 或 null
575577
*/
576-
public List<FolderItem> readDir(String path) throws IOException, UpException {
578+
public List<FolderItem> readDir(String path, Map<String, String> params) throws IOException, UpException {
577579

578-
String result = HttpAction(METHOD_GET, formatPath(path) + SEPARATOR);
580+
String result = HttpAction(METHOD_GET, formatPath(path) + SEPARATOR, params);
579581

580582
if (isEmpty(result))
581583
return null;
@@ -782,6 +784,18 @@ private String HttpAction(String method, String uri) throws IOException, UpExcep
782784
return HttpAction(method, uri, null, null, false);
783785
}
784786

787+
/**
788+
* 连接处理逻辑
789+
*
790+
* @param method 请求方式 {GET, POST, PUT, DELETE}
791+
* @param uri 请求地址
792+
* @param param 请求参数
793+
* @return 请求结果(字符串)或 null
794+
*/
795+
private String HttpAction(String method, String uri, Map<String, String> param) throws IOException, UpException {
796+
return HttpAction(method, uri, null, null, false, param);
797+
}
798+
785799
/**
786800
* 连接处理逻辑
787801
*
@@ -1200,6 +1214,36 @@ public enum PARAMS {
12001214
*/
12011215
KEY_X_UPYUN_MOVE_SOURCE("X-Upyun-Move-Source"),
12021216

1217+
/**
1218+
* 分页参数
1219+
* 分页开始位置,通过x-upyun-list-iter 响应头返回,所以第一次请求不需要填写
1220+
*/
1221+
KEY_X_LIST_ITER("x-list-iter"),
1222+
1223+
/**
1224+
* 分页参数
1225+
* 获取的文件数量,默认 100,最大 10000
1226+
*/
1227+
KEY_X_LIST_LIMIT("x-list-limit"),
1228+
1229+
/**
1230+
* 分页参数
1231+
* asc 或 desc,按文件名升序或降序排列。默认 asc
1232+
*/
1233+
KEY_X_LIST_ORDER("x-list-order"),
1234+
1235+
/**
1236+
* 分页参数
1237+
* application/json,返回json格式
1238+
*/
1239+
KEY_ACCEPT("Accept"),
1240+
1241+
/**
1242+
* 删除参数
1243+
* true 表示进行异步删除,不设置表示同步删除(默认)
1244+
*/
1245+
KEY_X_UPYUN_ASYNC("x-upyun-async"),
1246+
12031247
/**
12041248
* 缩略图类型之 "限定最长边,短边自适应",参数为像素值,如: 150
12051249
*/

src/main/java/com/upyun/ParallelUploader.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import okhttp3.Response;
66

77
import java.io.IOException;
8-
import java.io.RandomAccessFile;
98
import java.util.Map;
109
import java.util.concurrent.ExecutorService;
1110
import java.util.concurrent.Executors;

src/main/java/com/upyun/SerialUploader.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,6 @@ public int getNextPartIndex() {
7979
return nextPartIndex;
8080
}
8181

82-
/**
83-
* 设置上传进度监听
84-
*
85-
* @param onProgressListener 上传进度 listener
86-
*/
87-
public void setOnProgressListener(OnProgressListener onProgressListener) {
88-
this.onProgressListener = onProgressListener;
89-
}
90-
9182
public void setUuid(String uuid) {
9283
this.uuid = uuid;
9384
}
@@ -117,7 +108,7 @@ boolean processUpload() throws IOException, UpException {
117108
md5 = UpYunUtils.md5(data);
118109
}
119110

120-
String sign = UpYunUtils.sign("PUT", date, uri, bucketName, userName, password, md5);
111+
String sign = UpYunUtils.sign("PUT", date, uri, userName, password, md5);
121112

122113
Request.Builder builder = new Request.Builder()
123114
.url(url)

src/main/java/com/upyun/UpYunUtils.java

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public class UpYunUtils {
1212

13-
public static final String VERSION = "upyun-java-sdk/4.1.0";
13+
public static final String VERSION = "upyun-java-sdk/4.1.1";
1414

1515
/**
1616
* 计算policy
@@ -101,36 +101,6 @@ public static String md5(byte[] bytes) {
101101

102102
private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";
103103

104-
public static String sign(String method, String date, String uri, String bucket, String userName, String password, String md5) throws UpException {
105-
106-
StringBuilder sb = new StringBuilder();
107-
String sp = "&";
108-
sb.append(method);
109-
sb.append(sp);
110-
sb.append(uri);
111-
112-
sb.append(sp);
113-
sb.append(date);
114-
115-
if (md5 != null && md5.length() > 0) {
116-
sb.append(sp);
117-
sb.append(md5);
118-
}
119-
String raw = sb.toString().trim();
120-
byte[] hmac = null;
121-
try {
122-
hmac = calculateRFC2104HMACRaw(password, raw);
123-
} catch (Exception e) {
124-
throw new UpException("calculate SHA1 wrong.");
125-
}
126-
127-
if (hmac != null) {
128-
return "UPYUN " + userName + ":" + Base64Coder.encodeLines(hmac).trim();
129-
}
130-
131-
return null;
132-
}
133-
134104
public static String sign(String method, String date, String path, String userName, String password, String md5) throws UpException {
135105

136106
StringBuilder sb = new StringBuilder();

src/main/java/demo/FileBucketDemo.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
import java.io.File;
77
import java.io.IOException;
8+
import java.util.HashMap;
89
import java.util.List;
10+
import java.util.Map;
911

1012
import static org.junit.Assert.assertTrue;
1113

@@ -143,28 +145,28 @@ public static void testWriteFile() throws IOException, UpException {
143145
// 要传到upyun后的文件路径:多级目录
144146
String filePath2 = DIR_MORE + FILE_NAME;
145147

146-
/*
148+
/*
147149
* 上传方法1:文本内容直接上传
148-
*/
150+
*/
149151
boolean result1 = upyun.writeFile(filePath, content);
150152
System.out.println("1.上传 " + filePath + isSuccess(result1));
151153

152-
/*
154+
/*
153155
* 上传方法2:文本内容直接上传,可自动创建父级目录(最多10级)
154-
*/
156+
*/
155157
boolean result2 = upyun.writeFile(filePath2, content, true);
156158
System.out.println("2.上传 " + filePath2 + isSuccess(result2));
157159

158-
/*
160+
/*
159161
* 上传方法3:采用数据流模式上传文件(节省内存),可自动创建父级目录(最多10级)
160-
*/
162+
*/
161163
File file = new File(SAMPLE_TXT_FILE);
162164
boolean result3 = upyun.writeFile(filePath, file, true);
163165
System.out.println("3.上传 " + filePath + isSuccess(result3));
164166

165-
/*
166-
* 上传方法4:对待上传的文件设置 MD5 值,确保上传到 Upyun 的文件的完整性和正确性
167-
*/
167+
/*
168+
* 上传方法4:对待上传的文件设置 MD5 值,确保上传到 Upyun 的文件的完整性和正确性
169+
*/
168170
File file4 = new File(SAMPLE_TXT_FILE);
169171
// 设置待上传文件的 Content-MD5 值
170172
// 如果又拍云服务端收到的文件MD5值与用户设置的不一致,将回报 406 NotAcceptable 错误
@@ -198,15 +200,15 @@ public static void testReadFile() throws IOException, UpException {
198200
// upyun空间下存在的文件的路径
199201
String filePath = DIR_ROOT + FILE_NAME;
200202

201-
/*
202-
* 方法1:直接读取文本内容
203-
*/
203+
/*
204+
* 方法1:直接读取文本内容
205+
*/
204206
String datas = upyun.readFile(filePath);
205207
System.out.println(filePath + " 的文件内容:" + datas);
206208

207-
/*
208-
* 方法2:下载文件,采用数据流模式下载文件(节省内存)
209-
*/
209+
/*
210+
* 方法2:下载文件,采用数据流模式下载文件(节省内存)
211+
*/
210212
// 要写入的本地临时文件
211213
File file = File.createTempFile("upyunTempFile_", "");
212214

@@ -226,7 +228,7 @@ public static void testDeleteFile() throws IOException, UpException {
226228
String filePath = DIR_ROOT + FILE_NAME;
227229

228230
// 删除文件
229-
boolean result = upyun.deleteFile(filePath);
231+
boolean result = upyun.deleteFile(filePath, null);
230232

231233
System.out.println(filePath + " 删除" + isSuccess(result));
232234
System.out.println();
@@ -259,8 +261,12 @@ public static void testReadDir() throws IOException, UpException {
259261
// 参数可以换成其他目录路径
260262
String dirPath = DIR_ROOT;
261263

264+
Map<String, String> params = new HashMap<String, String>();
265+
266+
params.put(UpYun.PARAMS.KEY_X_LIST_LIMIT.getValue(), "10");
267+
262268
// 读取目录列表,将返回 List 或 NULL
263-
List<UpYun.FolderItem> items = upyun.readDir(dirPath);
269+
List<UpYun.FolderItem> items = upyun.readDir(dirPath, params);
264270

265271
if (null == items) {
266272
System.out.println("'" + dirPath + "'目录下没有文件。");

src/test/java/TestFileBucket.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.io.File;
66
import java.io.IOException;
7+
import java.util.HashMap;
78
import java.util.List;
89
import java.util.Map;
910

@@ -117,7 +118,11 @@ public class TestFileBucket {
117118
// String dirPath = DIR_ROOT;
118119
//
119120
// // 读取目录列表,将返回 List 或 NULL
120-
// List<UpYun.FolderItem> items = upyun.readDir(dirPath);
121+
// Map<String, String> params = new HashMap<String, String>();
122+
//
123+
// params.put(UpYun.PARAMS.KEY_X_LIST_LIMIT.getValue(), "10");
124+
//
125+
// List<UpYun.FolderItem> items = upyun.readDir(dirPath, params);
121126
//
122127
// assertTrue(items.size() > 0);
123128
// }
@@ -171,7 +176,7 @@ public class TestFileBucket {
171176
// String filePath = DIR_ROOT + FILE_NAME;
172177
//
173178
// // 删除文件
174-
// boolean result = upyun.deleteFile(filePath);
179+
// boolean result = upyun.deleteFile(filePath, null);
175180
//
176181
// assertTrue(result);
177182
// }

0 commit comments

Comments
 (0)