| | |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | |
| | | import com.ruoyi.common.core.lang.UUID; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.ruoyi.common.constant.Constants; |
| | |
| | | import com.ruoyi.common.exception.file.FileSizeLimitExceededException; |
| | | import com.ruoyi.common.exception.file.InvalidExtensionException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.IdUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.security.Md5Utils; |
| | | import com.ruoyi.framework.config.RuoYiConfig; |
| | | |
| | | /** |
| | |
| | | * 默认上传的地址 |
| | | */ |
| | | private static String defaultBaseDir = RuoYiConfig.getProfile(); |
| | | |
| | | private static int counter = 0; |
| | | |
| | | public static void setDefaultBaseDir(String defaultBaseDir) |
| | | { |
| | |
| | | { |
| | | String fileName = file.getOriginalFilename(); |
| | | String extension = getExtension(file); |
| | | fileName = DateUtils.datePath() + "/" + encodingFilename(fileName) + "." + extension; |
| | | fileName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + extension; |
| | | return fileName; |
| | | } |
| | | |
| | |
| | | { |
| | | desc.getParentFile().mkdirs(); |
| | | } |
| | | if (!desc.exists()) |
| | | { |
| | | desc.createNewFile(); |
| | | } |
| | | // 解决undertow文件上传bug,因底层实现不同,无需创建新文件 |
| | | // if (!desc.exists()) |
| | | // { |
| | | // desc.createNewFile(); |
| | | // } |
| | | return desc; |
| | | } |
| | | |
| | |
| | | String currentDir = StringUtils.substring(uploadDir, dirLastIndex); |
| | | String pathFileName = Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName; |
| | | return pathFileName; |
| | | } |
| | | |
| | | /** |
| | | * 编码文件名 |
| | | */ |
| | | private static final String encodingFilename(String fileName) |
| | | { |
| | | fileName = fileName.replace("_", " "); |
| | | fileName = Md5Utils.hash(fileName + System.nanoTime() + counter++); |
| | | return fileName; |
| | | } |
| | | |
| | | /** |