fix 头像上传问题

This commit is contained in:
不做码农 2022-04-11 15:50:23 +08:00
parent 846652c1af
commit 60ae296062

View File

@ -134,9 +134,7 @@ namespace ZR.Admin.WebApi.Controllers.System
LoginUser loginUser = Framework.JwtUtil.GetLoginUser(HttpContext); LoginUser loginUser = Framework.JwtUtil.GetLoginUser(HttpContext);
if (formFile == null) throw new CustomException("请选择文件"); if (formFile == null) throw new CustomException("请选择文件");
string fileExt = Path.GetExtension(formFile.FileName); SysFile file = await FileService.SaveFileToLocal(hostEnvironment.WebRootPath, "", "", HttpContext.GetName(), formFile);
string fileName = FileUtil.HashFileName() + (fileExt.IsEmpty() ? ".png" : fileExt);
SysFile file = await FileService.SaveFileToLocal(hostEnvironment.WebRootPath, fileName, "", HttpContext.GetName(), formFile);
UserService.UpdatePhoto(new SysUser() { Avatar = file.AccessUrl, UserId = loginUser.UserId }); UserService.UpdatePhoto(new SysUser() { Avatar = file.AccessUrl, UserId = loginUser.UserId });
return SUCCESS(new { imgUrl = file.AccessUrl }); return SUCCESS(new { imgUrl = file.AccessUrl });