refactor(music-houduan): 优化头像上传逻辑- 在 SingerServiceImpl 和 UserController 中添加 File 类的导入

- 修改头像上传逻辑,将物理路径转换为相对于项目目录的路径
- 统一处理头像上传的方式,提高代码复用性
This commit is contained in:
ikmkj
2025-07-27 16:00:59 +08:00
parent 9fe317bffb
commit 6a1e67bc99
2 changed files with 9 additions and 3 deletions

View File

@@ -15,6 +15,8 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
/**
* 用户控制器
*/
@@ -216,7 +218,8 @@ public class UserController {
@PostMapping("/upload/avatar")
public Result<String> uploadAvatar(@Parameter(description = "头像文件") @RequestParam("file") MultipartFile file) {
// 上传头像
String avatarUrl = fileService.uploadImage(file);
String avatarPhysicalPath = fileService.uploadImage(file);
String avatarUrl = avatarPhysicalPath.replace(System.getProperty("user.dir") + File.separator + "music-houduan", "").replace(File.separator, "/");
// 用户ID已经通过 SaCheckLogin 注解验证