|
@@ -0,0 +1,68 @@
|
|
1
|
+# 接口描述
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+- 接口请求域名: https://cepmtest.dhcccloud.com.cn 。
|
|
5
|
+- 请求大小不能大于20M
|
|
6
|
+- 包含Upload2Cmp和Upload两个接口,Upload2Cmp 上传视频,图片文件时会压缩文件大小
|
|
7
|
+
|
|
8
|
+# 输入参数
|
|
9
|
+| 参数 | 说明 | 类型 | 长度(字节) | 是否必填 |
|
|
10
|
+| --- | --- | --- | --- | --- |
|
|
11
|
+| - | -| - | - | - |
|
|
12
|
+# 调用示例
|
|
13
|
+
|
|
14
|
+#### java:
|
|
15
|
+``` java
|
|
16
|
+
|
|
17
|
+public static String uploadMultiFile(String path) {
|
|
18
|
+ String url ="https://cepmtest.dhcccloud.com.cn/upload2cmp/";
|
|
19
|
+ File file = new File(path);
|
|
20
|
+ MediaType mediaType=MediaType.Companion.parse("text/x-markdown; charset=utf-8");
|
|
21
|
+ RequestBody fileBody=RequestBody.Companion.create(file,mediaType);
|
|
22
|
+ RequestBody requestBody = new MultipartBody.Builder()
|
|
23
|
+ .setType(MultipartBody.FORM)
|
|
24
|
+ .addFormDataPart("file", file.getName().toLowerCase(), fileBody)
|
|
25
|
+ .build();
|
|
26
|
+ Request request = new Request.Builder()
|
|
27
|
+ .url(url)
|
|
28
|
+ .post(requestBody)
|
|
29
|
+ .build();
|
|
30
|
+ Response response = null;
|
|
31
|
+ try {
|
|
32
|
+ OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
|
|
33
|
+ response = okHttpClient.newCall(request).execute();
|
|
34
|
+ if (response.code() == 200) {
|
|
35
|
+ logger.info("uploadMultiFile; [postUrl="+url+", file="+path+", responseCode="+response.code()+"]");
|
|
36
|
+ return response.body().string();
|
|
37
|
+ } else {
|
|
38
|
+ logger.warning("uploadMultiFile请求失败,[url="+url+", file="+path+"]");
|
|
39
|
+ }
|
|
40
|
+ } catch (IOException e) {
|
|
41
|
+ logger.warning("uploadMultiFile请求失败,[url="+url+", file="+path+"]");
|
|
42
|
+ e.printStackTrace();
|
|
43
|
+ throw new RuntimeException("uploadMultiFile请求失败,url:" + url);
|
|
44
|
+ }
|
|
45
|
+ return null;
|
|
46
|
+}
|
|
47
|
+```
|
|
48
|
+#### javascript:
|
|
49
|
+``` javascript
|
|
50
|
+var formData = new FormData();
|
|
51
|
+formData.append("file", file);
|
|
52
|
+$.ajax({
|
|
53
|
+ url: 'https://cepmtest.dhcccloud.com.cn/upload2cmp/',
|
|
54
|
+ dataType: 'json',
|
|
55
|
+ type: 'POST',
|
|
56
|
+ async: true,
|
|
57
|
+ data: formData,
|
|
58
|
+ processData: false, // 使数据不做处理
|
|
59
|
+ contentType: false, // 不要设置Content-Type请求头
|
|
60
|
+ success: function (data) {
|
|
61
|
+ console.log(data);
|
|
62
|
+
|
|
63
|
+ },
|
|
64
|
+ error: response => {
|
|
65
|
+ console.error(response);
|
|
66
|
+ }
|
|
67
|
+});
|
|
68
|
+```
|