diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/file/FileException.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/file/FileException.java index ae61543..b19f2d8 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/file/FileException.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/file/FileException.java @@ -11,9 +11,9 @@ public class FileException extends BaseException { private static final long serialVersionUID = 1L; - public FileException(String code, Object[] args) + public FileException(String code, Object[] args, String msg) { - super("file", code, args, null); + super("file", code, args, msg); } } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/file/FileNameLengthLimitExceededException.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/file/FileNameLengthLimitExceededException.java index c425acd..0962ca5 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/file/FileNameLengthLimitExceededException.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/file/FileNameLengthLimitExceededException.java @@ -11,6 +11,6 @@ public class FileNameLengthLimitExceededException extends FileException public FileNameLengthLimitExceededException(int defaultFileNameLength) { - super("upload.filename.exceed.length", new Object[] { defaultFileNameLength }); + super("upload.filename.exceed.length", new Object[] { defaultFileNameLength }, "the filename is too long"); } } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/file/FileSizeLimitExceededException.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/file/FileSizeLimitExceededException.java index 0426067..f9a66b7 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/file/FileSizeLimitExceededException.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/exception/file/FileSizeLimitExceededException.java @@ -11,6 +11,6 @@ public class FileSizeLimitExceededException extends FileException public FileSizeLimitExceededException(long defaultMaxSize) { - super("upload.exceed.maxSize", new Object[] { defaultMaxSize }); + super("upload.exceed.maxSize", new Object[] { defaultMaxSize }, "the filesize is too large"); } } diff --git a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java index a0d1d4a..c7a2484 100644 --- a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java +++ b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java @@ -4,6 +4,8 @@ import java.io.File; import java.io.IOException; import java.nio.file.Paths; import java.util.Objects; + +import com.ruoyi.common.core.exception.file.FileException; import org.apache.commons.io.FilenameUtils; import org.springframework.web.multipart.MultipartFile; import com.ruoyi.common.core.exception.file.FileNameLengthLimitExceededException; @@ -46,6 +48,9 @@ public class FileUploadUtils { return upload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); } + catch (FileException fe){ + throw new IOException(fe.getDefaultMessage(), fe); + } catch (Exception e) { throw new IOException(e.getMessage(), e);