# 注意事项
- 接口请求域名: https://cepmtest.dhcccloud.com.cn 。
- 请求大小不能大于20M
- 包含Upload2Cmp和Upload两个接口,Upload2Cmp 上传视频,图片文件时会压缩文件大小
- 为不影响压缩效果,视频、图片的文件名请以正确的扩展名结尾
- 服务器文件每日自动清理
#
> 请求方式 ` POST https://cepmtest.dhcccloud.com.cn/upload2cmp/`
> 添加请求头 `Content-Type:multipart/form-data;`
| 请求参数 | 类型 | 是否必填 | 说明 |
| --- | --- | --- | --- |
| 无 | -| - | - |
| 返回参数 | 类型 | 是否必返 | 说明 |
| --- | --- | --- | --- |
| errcode | Num| 是 | 0交易成功
其它为异常情况 |
| errmsg | String | 否 | errcode不为0时有值 |
| data | String | 否 | 成功时返回文件存储路径,供其它接口使用 |
# 调用示例
#### java:
``` java
public static String uploadMultiFile(String path) {
String url ="https://cepmtest.dhcccloud.com.cn/upload2cmp/";
File file = new File(path);
MediaType mediaType=MediaType.Companion.parse("text/x-markdown; charset=utf-8");
RequestBody fileBody=RequestBody.Companion.create(file,mediaType);
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", file.getName().toLowerCase(), fileBody)
.build();
Request request = new Request.Builder()
.url(url)
.post(requestBody)
.build();
Response response = null;
try {
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
response = okHttpClient.newCall(request).execute();
if (response.code() == 200) {
logger.info("uploadMultiFile; [postUrl="+url+", file="+path+", responseCode="+response.code()+"]");
return response.body().string();
} else {
logger.warning("uploadMultiFile请求失败,[url="+url+", file="+path+"]");
}
} catch (IOException e) {
logger.warning("uploadMultiFile请求失败,[url="+url+", file="+path+"]");
e.printStackTrace();
throw new RuntimeException("uploadMultiFile请求失败,url:" + url);
}
return null;
}
```
#### javascript:
``` javascript
var formData = new FormData();
formData.append("file", file);
$.ajax({
url: 'https://cepmtest.dhcccloud.com.cn/upload2cmp/',
dataType: 'json',
type: 'POST',
async: true,
data: formData,
processData: false, // 使数据不做处理
contentType: false, // 不要设置Content-Type请求头
success: function (data) {
console.log(data);
},
error: response => {
console.error(response);
}
});
```