1
0

test-absolute-path-access.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>绝对路径文件访问测试</title>
  7. <style>
  8. body {
  9. font-family: Arial, sans-serif;
  10. max-width: 900px;
  11. margin: 50px auto;
  12. padding: 20px;
  13. background-color: #f5f5f5;
  14. }
  15. .container {
  16. background-color: white;
  17. padding: 30px;
  18. border-radius: 8px;
  19. box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  20. }
  21. h1 {
  22. color: #333;
  23. text-align: center;
  24. margin-bottom: 30px;
  25. }
  26. .section {
  27. margin-bottom: 30px;
  28. padding: 20px;
  29. border: 1px solid #ddd;
  30. border-radius: 5px;
  31. }
  32. .section h3 {
  33. color: #555;
  34. margin-top: 0;
  35. }
  36. input[type="text"], input[type="file"] {
  37. width: 100%;
  38. padding: 8px;
  39. border: 1px solid #ddd;
  40. border-radius: 4px;
  41. margin-bottom: 10px;
  42. box-sizing: border-box;
  43. }
  44. button {
  45. padding: 8px 16px;
  46. background-color: #007bff;
  47. color: white;
  48. border: none;
  49. border-radius: 4px;
  50. cursor: pointer;
  51. margin-right: 10px;
  52. margin-bottom: 10px;
  53. }
  54. button:hover {
  55. background-color: #0056b3;
  56. }
  57. button:disabled {
  58. background-color: #6c757d;
  59. cursor: not-allowed;
  60. }
  61. .example {
  62. background-color: #f8f9fa;
  63. padding: 15px;
  64. border-radius: 4px;
  65. margin: 10px 0;
  66. font-family: monospace;
  67. font-size: 14px;
  68. border-left: 4px solid #007bff;
  69. }
  70. .result {
  71. background-color: #d4edda;
  72. border: 1px solid #c3e6cb;
  73. padding: 15px;
  74. border-radius: 4px;
  75. margin-top: 10px;
  76. }
  77. .error {
  78. background-color: #f8d7da;
  79. border: 1px solid #f5c6cb;
  80. padding: 15px;
  81. border-radius: 4px;
  82. margin-top: 10px;
  83. }
  84. .info {
  85. background-color: #d1ecf1;
  86. border: 1px solid #bee5eb;
  87. padding: 15px;
  88. border-radius: 4px;
  89. margin-top: 10px;
  90. }
  91. .url-display {
  92. background-color: #f8f9fa;
  93. padding: 10px;
  94. border-radius: 4px;
  95. margin: 10px 0;
  96. font-family: monospace;
  97. font-size: 12px;
  98. word-break: break-all;
  99. border: 1px solid #dee2e6;
  100. }
  101. </style>
  102. </head>
  103. <body>
  104. <div class="container">
  105. <h1>绝对路径文件访问测试</h1>
  106. <div class="section">
  107. <h3>配置说明</h3>
  108. <div class="info">
  109. <strong>当前配置:</strong><br>
  110. 文件存储路径:/home/siwei/uploadPath<br>
  111. 文件服务地址:http://127.0.0.1:9202<br><br>
  112. <strong>支持的访问方式:</strong><br>
  113. 方式1:http://127.0.0.1:9202/statics/相对路径<br>
  114. 方式2:http://127.0.0.1:9202/home/siwei/uploadPath/相对路径 (新增)
  115. </div>
  116. </div>
  117. <div class="section">
  118. <h3>1. 文件上传测试</h3>
  119. <p>先上传一个文件,获取完整路径用于测试</p>
  120. <input type="file" id="fileInput" accept="*/*">
  121. <button onclick="uploadFile()" id="uploadBtn">上传文件</button>
  122. <div id="uploadResult" style="display:none;"></div>
  123. </div>
  124. <div class="section">
  125. <h3>2. 绝对路径访问测试</h3>
  126. <p>输入完整的文件路径进行访问测试</p>
  127. <input type="text" id="absolutePath" placeholder="输入绝对路径,如:/home/siwei/uploadPath/2025/08/01/文件_20250801154318A001.zip">
  128. <button onclick="testAbsolutePath()">测试绝对路径访问</button>
  129. <button onclick="fillExamplePath()">填入示例路径</button>
  130. <div id="absoluteResult" style="display:none;"></div>
  131. </div>
  132. <div class="section">
  133. <h3>3. 路径对比测试</h3>
  134. <p>对比两种访问方式的效果</p>
  135. <input type="text" id="relativePath" placeholder="输入相对路径,如:2025/08/01/文件_20250801154318A001.zip">
  136. <button onclick="testBothPaths()">对比测试</button>
  137. <div id="compareResult" style="display:none;"></div>
  138. </div>
  139. <div class="section">
  140. <h3>示例路径</h3>
  141. <div class="example">
  142. <strong>假设文件路径:</strong><br>
  143. 完整路径:/home/siwei/uploadPath/2025/08/01/文件_20250801154318A001.zip<br><br>
  144. <strong>访问方式:</strong><br>
  145. 方式1:http://127.0.0.1:9202/statics/2025/08/01/文件_20250801154318A001.zip<br>
  146. 方式2:http://127.0.0.1:9202/home/siwei/uploadPath/2025/08/01/文件_20250801154318A001.zip
  147. </div>
  148. </div>
  149. </div>
  150. <script>
  151. function uploadFile() {
  152. const fileInput = document.getElementById('fileInput');
  153. const file = fileInput.files[0];
  154. const resultDiv = document.getElementById('uploadResult');
  155. const uploadBtn = document.getElementById('uploadBtn');
  156. if (!file) {
  157. alert('请选择文件');
  158. return;
  159. }
  160. const formData = new FormData();
  161. formData.append('file', file);
  162. uploadBtn.disabled = true;
  163. uploadBtn.textContent = '上传中...';
  164. resultDiv.style.display = 'block';
  165. resultDiv.innerHTML = '<div class="info">正在上传文件...</div>';
  166. fetch('http://127.0.0.1:9202/upload', {
  167. method: 'POST',
  168. body: formData
  169. })
  170. .then(response => response.json())
  171. .then(data => {
  172. uploadBtn.disabled = false;
  173. uploadBtn.textContent = '上传文件';
  174. if (data.code === 200) {
  175. const result = data.data;
  176. const absolutePath = result.path;
  177. const relativePath = absolutePath.replace('/home/siwei/uploadPath/', '');
  178. resultDiv.innerHTML = `
  179. <div class="result">
  180. <strong>✅ 上传成功!</strong><br>
  181. 文件名:${result.name}<br>
  182. 完整路径:${result.path}<br>
  183. 相对路径:${relativePath}<br><br>
  184. <strong>测试链接:</strong><br>
  185. <button onclick="window.open('http://127.0.0.1:9202/statics/${relativePath}', '_blank')">方式1:/statics 访问</button>
  186. <button onclick="window.open('http://127.0.0.1:9202${absolutePath}', '_blank')">方式2:绝对路径访问</button><br><br>
  187. <button onclick="document.getElementById('absolutePath').value='${absolutePath}'">填入绝对路径测试框</button>
  188. <button onclick="document.getElementById('relativePath').value='${relativePath}'">填入相对路径测试框</button>
  189. </div>
  190. `;
  191. } else {
  192. resultDiv.innerHTML = `<div class="error">❌ 上传失败:${data.msg}</div>`;
  193. }
  194. })
  195. .catch(error => {
  196. uploadBtn.disabled = false;
  197. uploadBtn.textContent = '上传文件';
  198. console.error('Error:', error);
  199. resultDiv.innerHTML = `<div class="error">❌ 上传异常:${error.message}</div>`;
  200. });
  201. }
  202. function testAbsolutePath() {
  203. const absolutePath = document.getElementById('absolutePath').value.trim();
  204. const resultDiv = document.getElementById('absoluteResult');
  205. if (!absolutePath) {
  206. alert('请输入绝对路径');
  207. return;
  208. }
  209. const testUrl = `http://127.0.0.1:9202${absolutePath}`;
  210. resultDiv.style.display = 'block';
  211. resultDiv.innerHTML = `
  212. <div class="info">
  213. <strong>测试URL:</strong><br>
  214. <div class="url-display">${testUrl}</div>
  215. <button onclick="window.open('${testUrl}', '_blank')">在新窗口打开</button>
  216. <button onclick="testUrlAccess('${testUrl}', 'absoluteResult')">测试访问状态</button>
  217. </div>
  218. `;
  219. }
  220. function testBothPaths() {
  221. const relativePath = document.getElementById('relativePath').value.trim();
  222. const resultDiv = document.getElementById('compareResult');
  223. if (!relativePath) {
  224. alert('请输入相对路径');
  225. return;
  226. }
  227. const staticUrl = `http://127.0.0.1:9202/statics/${relativePath}`;
  228. const absoluteUrl = `http://127.0.0.1:9202/home/siwei/uploadPath/${relativePath}`;
  229. resultDiv.style.display = 'block';
  230. resultDiv.innerHTML = `
  231. <div class="info">
  232. <strong>方式1 - /statics 前缀:</strong><br>
  233. <div class="url-display">${staticUrl}</div>
  234. <button onclick="window.open('${staticUrl}', '_blank')">打开</button>
  235. <button onclick="testUrlAccess('${staticUrl}', 'static-status')">测试</button>
  236. <span id="static-status"></span><br><br>
  237. <strong>方式2 - 绝对路径:</strong><br>
  238. <div class="url-display">${absoluteUrl}</div>
  239. <button onclick="window.open('${absoluteUrl}', '_blank')">打开</button>
  240. <button onclick="testUrlAccess('${absoluteUrl}', 'absolute-status')">测试</button>
  241. <span id="absolute-status"></span>
  242. </div>
  243. `;
  244. }
  245. function testUrlAccess(url, statusElementId) {
  246. const statusElement = document.getElementById(statusElementId);
  247. if (statusElement) {
  248. statusElement.innerHTML = ' 🔄 测试中...';
  249. }
  250. fetch(url, { method: 'HEAD' })
  251. .then(response => {
  252. if (statusElement) {
  253. if (response.ok) {
  254. statusElement.innerHTML = ' ✅ 可访问';
  255. statusElement.style.color = 'green';
  256. } else {
  257. statusElement.innerHTML = ` ❌ ${response.status}`;
  258. statusElement.style.color = 'red';
  259. }
  260. }
  261. })
  262. .catch(error => {
  263. if (statusElement) {
  264. statusElement.innerHTML = ' ❌ 网络错误';
  265. statusElement.style.color = 'red';
  266. }
  267. });
  268. }
  269. function fillExamplePath() {
  270. document.getElementById('absolutePath').value = '/home/siwei/uploadPath/2025/08/01/文件_20250801154318A001.zip';
  271. }
  272. </script>
  273. </body>
  274. </html>