生态文档
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

文件服务器接口.md 2.3KB

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