|
|
@@ -2,9 +2,6 @@ package com.fs.common.utils.file;
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
-import com.fs.common.exception.file.FileNameLengthLimitExceededException;
|
|
|
-import com.fs.common.exception.file.FileSizeLimitExceededException;
|
|
|
-import com.fs.common.exception.file.InvalidExtensionException;
|
|
|
import com.fs.common.exception.file.OssException;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
|
|
|
@@ -33,7 +30,6 @@ public class OssUploadUtils
|
|
|
* 校验上传文件并返回经文件头验证后的后缀(带点,如 ".jpg")
|
|
|
*/
|
|
|
public static String validateAndGetSuffix(MultipartFile file)
|
|
|
- throws FileSizeLimitExceededException, FileNameLengthLimitExceededException, InvalidExtensionException
|
|
|
{
|
|
|
if (file == null || file.isEmpty())
|
|
|
{
|
|
|
@@ -47,19 +43,19 @@ public class OssUploadUtils
|
|
|
}
|
|
|
if (fileName.length() > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
|
|
|
{
|
|
|
- throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
|
|
|
+ throw new OssException("文件名长度超出限制");
|
|
|
}
|
|
|
|
|
|
long size = file.getSize();
|
|
|
if (size > OSS_MAX_SIZE)
|
|
|
{
|
|
|
- throw new FileSizeLimitExceededException(OSS_MAX_SIZE / 1024 / 1024);
|
|
|
+ throw new OssException("文件大小超出限制,最大允许 " + (OSS_MAX_SIZE / 1024 / 1024) + "MB");
|
|
|
}
|
|
|
|
|
|
String extension = FileUploadUtils.getExtension(file);
|
|
|
if (!FileUploadUtils.isAllowedExtension(extension, OSS_ALLOWED_EXTENSION))
|
|
|
{
|
|
|
- throw new InvalidExtensionException(OSS_ALLOWED_EXTENSION, extension, fileName);
|
|
|
+ throw new OssException("文件类型不允许上传");
|
|
|
}
|
|
|
|
|
|
byte[] bytes;
|