guoyu/视频无法打开问题诊断.md

115 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 视频无法打开问题诊断
## 🔍 问题分析
### 当前文件路径情况
```
实际文件位置D:\wwwroot\study_web\web\profile\upload\upload\2025\11\18\xxx.mp4
^^^^^^ 重复了!
```
### 路径生成逻辑
1. **配置文件**`profile = D:\wwwroot\study_web\web\profile`
2. **RuoYiConfig.getUploadPath()**`profile + "/upload"` = `D:\wwwroot\study_web\web\profile\upload`
3. **文件上传时**:在 `uploadPath` 下再创建日期目录:`upload/2025/11/18/`
4. **最终物理路径**`D:\wwwroot\study_web\web\profile\upload\2025\11\18\xxx.mp4` ✅ 正常
### 为什么会有两个 upload
**可能原因:**
1. 之前的配置是 `profile = D:\wwwroot\study_web\web\profile\upload`
2. 导致实际上传路径变成:`D:\wwwroot\study_web\web\profile\upload\upload\...`
3. 文件已经上传到了错误的路径
### URL 访问映射
```
URL 路径:/profile/**
映射到file:D:\wwwroot\study_web\web\profile/
示例:
URL: http://192.168.0.106:30091/profile/upload/upload/2025/11/18/xxx.mp4
映射: D:\wwwroot\study_web\web\profile/upload/upload/2025/11/18/xxx.mp4
```
---
## 🔧 解决方案
### 方案一:移动文件到正确位置(推荐)
将文件从错误位置移动到正确位置:
```
D:\wwwroot\study_web\web\profile\upload\upload\2025\11\18\
D:\wwwroot\study_web\web\profile\upload\2025\11\18\
```
**操作步骤:**
1. **备份数据库**(重要!)
2. **移动文件**
```powershell
# 在 PowerShell 中执行
cd D:\wwwroot\study_web\web\profile\upload
# 将 upload 子目录下的所有文件移动到当前目录
Move-Item -Path "upload\*" -Destination "." -Force
# 删除空的 upload 目录
Remove-Item -Path "upload" -Recurse -Force
```
3. **更新数据库中的文件路径**
```sql
-- 更新课件表中的文件路径(去掉多余的 /upload
UPDATE study_courseware
SET file_path = REPLACE(file_path, '/profile/upload/upload/', '/profile/upload/')
WHERE file_path LIKE '/profile/upload/upload/%';
-- 检查更新结果
SELECT id, name, file_path
FROM study_courseware
WHERE file_path LIKE '/profile/upload/%'
LIMIT 10;
```
4. **重启后端服务**
5. **测试视频访问**
---
### 方案二:修改静态资源映射(临时方案)
如果不想移动文件,可以修改资源映射配置,让 `/profile/upload/upload/` 也能访问到文件。
**修改 ResourcesConfig.java**
```java
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry)
{
/** 本地文件上传路径 */
registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**")
.addResourceLocations("file:" + RuoYiConfig.getProfile() + "/")
.setCacheControl(CacheControl.maxAge(7, TimeUnit.DAYS).cachePublic())
.resourceChain(true);
// 临时方案:兼容旧的错误路径
registry.addResourceHandler("/profile/upload/upload/**")
.addResourceLocations("file:" + RuoYiConfig.getProfile() + "/upload/upload/")
.setCacheControl(CacheControl.maxAge(7, TimeUnit.DAYS).cachePublic())
.resourceChain(true);
}
```
**缺点:** 这只是临时方案,不解决根本问题。
---
### 方案三:批量修复(推荐用于生产环境)
创建一个批处理脚本自动修复: