生态文档
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.2KB

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