|
|
@ -11,6 +11,7 @@ import com.ruoyi.common.core.exception.file.FileSizeLimitExceededException; |
|
|
|
import com.ruoyi.common.core.exception.file.InvalidExtensionException; |
|
|
|
import com.ruoyi.common.core.exception.file.InvalidExtensionException; |
|
|
|
import com.ruoyi.common.core.utils.DateUtils; |
|
|
|
import com.ruoyi.common.core.utils.DateUtils; |
|
|
|
import com.ruoyi.common.core.utils.StringUtils; |
|
|
|
import com.ruoyi.common.core.utils.StringUtils; |
|
|
|
|
|
|
|
import com.ruoyi.common.core.utils.file.FileTypeUtils; |
|
|
|
import com.ruoyi.common.core.utils.file.MimeTypeUtils; |
|
|
|
import com.ruoyi.common.core.utils.file.MimeTypeUtils; |
|
|
|
import com.ruoyi.common.core.utils.uuid.Seq; |
|
|
|
import com.ruoyi.common.core.utils.uuid.Seq; |
|
|
|
|
|
|
|
|
|
|
@ -88,7 +89,7 @@ public class FileUploadUtils |
|
|
|
public static final String extractFilename(MultipartFile file) |
|
|
|
public static final String extractFilename(MultipartFile file) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), |
|
|
|
return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), |
|
|
|
FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file)); |
|
|
|
FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), FileTypeUtils.getExtension(file)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException |
|
|
|
private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException |
|
|
@ -128,7 +129,7 @@ public class FileUploadUtils |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String fileName = file.getOriginalFilename(); |
|
|
|
String fileName = file.getOriginalFilename(); |
|
|
|
String extension = getExtension(file); |
|
|
|
String extension = FileTypeUtils.getExtension(file); |
|
|
|
if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension)) |
|
|
|
if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION) |
|
|
|
if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION) |
|
|
@ -176,20 +177,4 @@ public class FileUploadUtils |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 获取文件名的后缀 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param file 表单文件 |
|
|
|
|
|
|
|
* @return 后缀名 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static final String getExtension(MultipartFile file) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
String extension = FilenameUtils.getExtension(file.getOriginalFilename()); |
|
|
|
|
|
|
|
if (StringUtils.isEmpty(extension)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
extension = MimeTypeUtils.getExtension(Objects.requireNonNull(file.getContentType())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return extension; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |