|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- # 接口描述
-
-
- - 接口请求域名: https://cepmtest.dhcccloud.com.cn 。
- - 请求大小不能大于20M
- - 包含Upload2Cmp和Upload两个接口,Upload2Cmp 上传视频,图片文件时会压缩文件大小
-
- # 输入参数
- | 参数 | 说明 | 类型 | 长度(字节) | 是否必填 |
- | --- | --- | --- | --- | --- |
- | - | -| - | - | - |
- # 调用示例
-
- #### 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);
- }
- });
- ```
|