From 7f886e4cd10f2b337b6dcbc923119e66fc2f5161 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sun, 22 May 2022 18:18:12 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=A4=B4=E5=83=8F=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E9=99=90=E5=88=B6=E5=8F=AA=E8=83=BD=E4=B8=BA=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/file/InvalidExtensionException.java | 2 +- .../project/system/controller/SysProfileController.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ruoyi/common/exception/file/InvalidExtensionException.java b/src/main/java/com/ruoyi/common/exception/file/InvalidExtensionException.java index 6819537..a483f46 100644 --- a/src/main/java/com/ruoyi/common/exception/file/InvalidExtensionException.java +++ b/src/main/java/com/ruoyi/common/exception/file/InvalidExtensionException.java @@ -18,7 +18,7 @@ public class InvalidExtensionException extends FileUploadException public InvalidExtensionException(String[] allowedExtension, String extension, String filename) { - super("filename : [" + filename + "], extension : [" + extension + "], allowed extension : [" + Arrays.toString(allowedExtension) + "]"); + super("文件[" + filename + "]后缀[" + extension + "]不正确,请上传 [" + Arrays.toString(allowedExtension) + "]格式文件"); this.allowedExtension = allowedExtension; this.extension = extension; this.filename = filename; diff --git a/src/main/java/com/ruoyi/project/system/controller/SysProfileController.java b/src/main/java/com/ruoyi/project/system/controller/SysProfileController.java index fc37940..2da04ba 100644 --- a/src/main/java/com/ruoyi/project/system/controller/SysProfileController.java +++ b/src/main/java/com/ruoyi/project/system/controller/SysProfileController.java @@ -1,6 +1,5 @@ package com.ruoyi.project.system.controller; -import java.io.IOException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -14,6 +13,7 @@ import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.file.FileUploadUtils; +import com.ruoyi.common.utils.file.MimeTypeUtils; import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; import com.ruoyi.framework.config.RuoYiConfig; @@ -121,12 +121,12 @@ public class SysProfileController extends BaseController */ @Log(title = "用户头像", businessType = BusinessType.UPDATE) @PostMapping("/avatar") - public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException + public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws Exception { if (!file.isEmpty()) { LoginUser loginUser = getLoginUser(); - String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file); + String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION); if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) { AjaxResult ajax = AjaxResult.success();