upload.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. export default async(url='',file={},servletType=1)=>{
  2. var header_content = {
  3. // 'Content-Type': 'multipart/form-data',
  4. "type":servletType,
  5. "fileid":file.fileId,
  6. "range":0,
  7. "totalsize":file.file.size,
  8. "filecreatetime":getNowFormatDate(),
  9. "filename":typeof(file.file.name) ==="undefined"?"":encodeURI(file.file.name),
  10. };
  11. let formData = new FormData();
  12. formData.append("file", file.file);
  13. let requestConfig = {
  14. credentials: 'include',
  15. method: 'post',
  16. headers: header_content,
  17. mode: "cors",
  18. cache: "force-cache",
  19. body: formData
  20. };
  21. url = fileManagerIp+"filemanager/FileUploadAndDownloadServlet";
  22. const response = await fetch(url, requestConfig);
  23. // let domResult = new DOMParser().parseFromString(response,"text/xml");
  24. // let resultCode = domResult.getElementsByTagName("resultCode")[0].innerHTML;
  25. let resultCode = 1;
  26. if("OK" == response.statusText){
  27. resultCode = 0;
  28. }
  29. return resultCode;
  30. }
  31. let fileManagerIp = "/";
  32. export const prevPath = (fileId) =>{
  33. var header_content = {
  34. "type":2,
  35. "fileid":fileId,
  36. "range":0,
  37. "filecreatetime":getNowFormatDate(),
  38. };
  39. let formData = new FormData();
  40. let requestConfig = {
  41. credentials: 'include',
  42. method: 'post',
  43. headers: header_content,
  44. mode: "cors",
  45. cache: "force-cache",
  46. body: formData
  47. };
  48. let url = fileManagerIp+"filemanager/FileUploadAndDownloadServlet";
  49. const response = fetch(url, requestConfig);
  50. // let domResult = new DOMParser().parseFromString(response,"text/xml");
  51. // let resultCode = domResult.getElementsByTagName("resultCode")[0].innerHTML;
  52. // let resultCode = 1;
  53. // if("OK" == response.statusText){
  54. // resultCode = 0;
  55. // }
  56. return response;
  57. }
  58. function getNowFormatDate() {
  59. /**
  60. * 获取当前时间
  61. */
  62. var now = new Date();
  63. var year = now.getFullYear(); //年
  64. var month = now.getMonth() + 1; //月
  65. var day = now.getDate(); //日
  66. var hh = now.getHours(); //时
  67. var mm = now.getMinutes(); //分
  68. var ss = now.getSeconds(); //秒
  69. var clock = year + "-";
  70. if(month < 10)
  71. clock += "0";
  72. clock += month + "-";
  73. if(day < 10)
  74. clock += "0";
  75. clock += day + " ";
  76. if(hh < 10)
  77. clock += "0";
  78. clock += hh + ":";
  79. if(mm < 10) clock += '0';
  80. clock += mm + ":";
  81. if(ss < 10) clock += '0';
  82. clock += ss;
  83. return(clock);
  84. }