refactor(music-houduan): 优化头像上传逻辑- 在 SingerServiceImpl 和 UserController 中添加 File 类的导入
- 修改头像上传逻辑,将物理路径转换为相对于项目目录的路径 - 统一处理头像上传的方式,提高代码复用性
This commit is contained in:
@@ -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 注解验证
|
||||
|
||||
|
||||
Reference in New Issue
Block a user