生态文档
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

文件服务器接口.md 2.2KB

接口描述

  • 接口请求域名: https://cepmtest.dhcccloud.com.cn
  • 请求大小不能大于20M
  • 包含Upload2Cmp和Upload两个接口,Upload2Cmp 上传视频,图片文件时会压缩文件大小

输入参数

参数 说明 类型 长度(字节) 是否必填
- - - - -

调用示例

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:

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);
    }
});