-
Notifications
You must be signed in to change notification settings - Fork 49
/
ConvertDemo.java
70 lines (49 loc) · 1.96 KB
/
ConvertDemo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package demo;
import com.upyun.ConvertHandler;
import com.upyun.Result;
import com.upyun.UpException;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class ConvertDemo {
// 运行前先设置好以下三个参数
private static final String BUCKET_NAME = "空间名称";
private static final String OPERATOR_NAME = "操作员名称";
private static final String OPERATOR_PWD = "操作员密码";
public static void main(String[] args) {
testConvert();
}
private static void testConvert() {
ConvertHandler handler = new ConvertHandler(BUCKET_NAME, OPERATOR_NAME, OPERATOR_PWD);
//初始化参数组 Map
Map<String, Object> paramsMap = new HashMap<String, Object>();
paramsMap.put(ConvertHandler.Params.BUCKET_NAME, BUCKET_NAME);
paramsMap.put(ConvertHandler.Params.NOTIFY_URL, "http://httpbin.org/post");
paramsMap.put(ConvertHandler.Params.APP_NAME, "uconvert");
//已json格式生成任务信息
JSONArray array = new JSONArray();
JSONObject json = new JSONObject();
//添加处理参数
json.put(ConvertHandler.Params.SOURCE, "/test_ppt.pptx");
json.put(ConvertHandler.Params.SAVE_AS, "/result/convert/convert");
array.put(json);
//添加任务信息
paramsMap.put(ConvertHandler.Params.TASKS, array);
try {
Result result = handler.process(paramsMap);
assertNotNull(result);
assertTrue(result.isSucceed());
assertNotNull(result.getMsg());
String[] ids = handler.getTaskId(result.getMsg());
assertNotNull(ids);
} catch (IOException e) {
e.printStackTrace();
} catch (UpException e) {
e.printStackTrace();
}
}
}