112 lines
2.9 KiB
Markdown
112 lines
2.9 KiB
Markdown
|
|
# 图片上传配置修复
|
|||
|
|
|
|||
|
|
## 问题描述
|
|||
|
|
|
|||
|
|
用户反馈看到旧的图片URL格式:
|
|||
|
|
- `http://localhost:8080/uploads/images/2026/01/08/xxx.png`
|
|||
|
|
- `http://example.com/xxx.jpg`
|
|||
|
|
|
|||
|
|
## 问题原因
|
|||
|
|
|
|||
|
|
1. **数据库旧数据**: 历史上传的图片使用旧URL格式(不需要清理)
|
|||
|
|
2. **配置缺失**: `application.yml` 中缺少 `file.upload.url` 配置项
|
|||
|
|
3. **旧代码兼容**: `LearningRecordServiceImpl` 中有旧的上传方法使用该配置
|
|||
|
|
|
|||
|
|
## 解决方案
|
|||
|
|
|
|||
|
|
### 1. 更新 application.yml
|
|||
|
|
|
|||
|
|
添加了 `file.upload.url` 配置项(兼容旧代码):
|
|||
|
|
|
|||
|
|
```yaml
|
|||
|
|
file:
|
|||
|
|
upload:
|
|||
|
|
mode: remote
|
|||
|
|
url-prefix: https://px.ddn-ai.cloud/uploads/ # 新系统使用
|
|||
|
|
url: https://px.ddn-ai.cloud/uploads # 旧系统兼容
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 2. 当前上传流程
|
|||
|
|
|
|||
|
|
**新上传系统**(推荐使用):
|
|||
|
|
```
|
|||
|
|
小程序
|
|||
|
|
→ http://localhost:8089/api/file/upload (本地后端)
|
|||
|
|
→ FileUploadService.uploadFile()
|
|||
|
|
→ 远程上传到 https://px.ddn-ai.cloud/api/file/upload/direct
|
|||
|
|
→ 保存到 /www/wwwroot/px.ddn-ai.cloud/Image/
|
|||
|
|
→ 返回 https://px.ddn-ai.cloud/uploads/20260125_xxx.jpg
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**旧上传方法**(已废弃,但保留兼容):
|
|||
|
|
```
|
|||
|
|
LearningRecordServiceImpl.uploadFile()
|
|||
|
|
→ 使用 file.upload.url 配置
|
|||
|
|
→ 返回 https://px.ddn-ai.cloud/uploads/xxx/xxx/xxx.jpg
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 验证步骤
|
|||
|
|
|
|||
|
|
### 1. 重启后端服务
|
|||
|
|
```bash
|
|||
|
|
# 停止旧进程
|
|||
|
|
# 重新运行后端
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 2. 测试上传功能
|
|||
|
|
- 打开小程序陪伴员端
|
|||
|
|
- 进入签到页面
|
|||
|
|
- 上传一张图片
|
|||
|
|
- 检查返回的URL格式
|
|||
|
|
|
|||
|
|
### 3. 期望结果
|
|||
|
|
返回的URL应该是:
|
|||
|
|
```
|
|||
|
|
https://px.ddn-ai.cloud/uploads/20260125_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.jpg
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 配置说明
|
|||
|
|
|
|||
|
|
### 新系统配置(推荐)
|
|||
|
|
- **接口**: `/api/file/upload`
|
|||
|
|
- **Service**: `FileUploadService`
|
|||
|
|
- **配置项**: `file.upload.url-prefix`
|
|||
|
|
- **URL格式**: `https://px.ddn-ai.cloud/uploads/20260125_xxx.jpg`
|
|||
|
|
|
|||
|
|
### 旧系统配置(兼容)
|
|||
|
|
- **接口**: 无(Service内部方法)
|
|||
|
|
- **Service**: `LearningRecordServiceImpl.uploadFile()`
|
|||
|
|
- **配置项**: `file.upload.url`
|
|||
|
|
- **URL格式**: `https://px.ddn-ai.cloud/uploads/images/20260125/xxx.jpg`
|
|||
|
|
|
|||
|
|
## 注意事项
|
|||
|
|
|
|||
|
|
1. **旧数据不影响**: 数据库中的旧URL是历史数据,不影响新上传
|
|||
|
|
2. **统一使用新接口**: 建议所有上传都使用 `/api/file/upload` 接口
|
|||
|
|
3. **配置已兼容**: 新旧系统配置都已正确设置
|
|||
|
|
|
|||
|
|
## 后续工作
|
|||
|
|
|
|||
|
|
根据 `[一次性]小程序图片上传更新清单-2026-01-25.md`,还需要更新以下页面使用新的上传工具:
|
|||
|
|
|
|||
|
|
**高优先级**:
|
|||
|
|
- [ ] 签退页面 (checkout.vue)
|
|||
|
|
- [ ] 成长记录创建 (record-create.vue)
|
|||
|
|
- [ ] 每日记录 (daily-record.vue)
|
|||
|
|
|
|||
|
|
**中优先级**:
|
|||
|
|
- [ ] 管理师申请 (apply.vue)
|
|||
|
|
- [ ] 陪伴员资料 (profile.vue)
|
|||
|
|
|
|||
|
|
**低优先级**:
|
|||
|
|
- [ ] 视频上传 (upload.vue)
|
|||
|
|
- [ ] 反馈创建 (create.vue)
|
|||
|
|
|
|||
|
|
## 完成状态
|
|||
|
|
|
|||
|
|
✅ 配置文件已更新
|
|||
|
|
✅ 新上传系统已就绪
|
|||
|
|
✅ 旧系统已兼容
|
|||
|
|
⏳ 等待重启后端测试
|
|||
|
|
⏳ 等待更新其他页面
|