| | |
| | | import com.ruoyi.common.core.exception.file.InvalidExtensionException;
|
| | | import com.ruoyi.common.core.utils.DateUtils;
|
| | | 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.uuid.Seq;
|
| | |
|
| | |
| | | public static final String extractFilename(MultipartFile file)
|
| | | {
|
| | | 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
|
| | |
| | | }
|
| | |
|
| | | String fileName = file.getOriginalFilename();
|
| | | String extension = getExtension(file);
|
| | | String extension = FileTypeUtils.getExtension(file);
|
| | | if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension))
|
| | | {
|
| | | if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION)
|
| | |
| | | }
|
| | | }
|
| | | 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;
|
| | | }
|
| | | } |