生态文档
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

文件服务器接口.md 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # 注意事项
  2. - 接口请求域名: https://cepmtest.dhcccloud.com.cn 。
  3. - 请求大小不能大于20M
  4. - 包含Upload2Cmp和Upload两个接口,Upload2Cmp 上传视频,图片文件时会压缩文件大小
  5. - 为不影响压缩效果,视频、图片的文件名请以正确的扩展名结尾
  6. - 服务器文件每日自动清理
  7. #
  8. > 请求方式 ` POST https://cepmtest.dhcccloud.com.cn/upload2cmp/`
  9. > 添加请求头 `Content-Type:multipart/form-data;`
  10. | 请求参数 | 类型 | 是否必填 | 说明 |
  11. | --- | --- | --- | --- | --- |
  12. | 无 | -| - | - |
  13. | 返回参数 | 类型 | 是否比返 | 说明 |
  14. | --- | --- | --- | --- | --- |
  15. | errcode | Num| 是 | 0交易成功<br>其它为异常情况 |
  16. | errmsg | String | 否 | errcode不为0时有值 |
  17. | data | String | 否 | 成功时返回文件存储路径,供其它接口使用 |
  18. # 调用示例
  19. #### java:
  20. ``` java
  21. public static String uploadMultiFile(String path) {
  22. String url ="https://cepmtest.dhcccloud.com.cn/upload2cmp/";
  23. File file = new File(path);
  24. MediaType mediaType=MediaType.Companion.parse("text/x-markdown; charset=utf-8");
  25. RequestBody fileBody=RequestBody.Companion.create(file,mediaType);
  26. RequestBody requestBody = new MultipartBody.Builder()
  27. .setType(MultipartBody.FORM)
  28. .addFormDataPart("file", file.getName().toLowerCase(), fileBody)
  29. .build();
  30. Request request = new Request.Builder()
  31. .url(url)
  32. .post(requestBody)
  33. .build();
  34. Response response = null;
  35. try {
  36. OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
  37. response = okHttpClient.newCall(request).execute();
  38. if (response.code() == 200) {
  39. logger.info("uploadMultiFile; [postUrl="+url+", file="+path+", responseCode="+response.code()+"]");
  40. return response.body().string();
  41. } else {
  42. logger.warning("uploadMultiFile请求失败,[url="+url+", file="+path+"]");
  43. }
  44. } catch (IOException e) {
  45. logger.warning("uploadMultiFile请求失败,[url="+url+", file="+path+"]");
  46. e.printStackTrace();
  47. throw new RuntimeException("uploadMultiFile请求失败,url:" + url);
  48. }
  49. return null;
  50. }
  51. ```
  52. #### javascript:
  53. ``` javascript
  54. var formData = new FormData();
  55. formData.append("file", file);
  56. $.ajax({
  57. url: 'https://cepmtest.dhcccloud.com.cn/upload2cmp/',
  58. dataType: 'json',
  59. type: 'POST',
  60. async: true,
  61. data: formData,
  62. processData: false, // 使数据不做处理
  63. contentType: false, // 不要设置Content-Type请求头
  64. success: function (data) {
  65. console.log(data);
  66. },
  67. error: response => {
  68. console.error(response);
  69. }
  70. });
  71. ```