mirror of https://gitee.com/y_project/RuoYi.git
文件路径更换
parent
7922cabb5b
commit
dcd6f2252f
|
@ -8,8 +8,8 @@ ruoyi:
|
|||
copyrightYear: 2019
|
||||
# 实例演示开关
|
||||
demoEnabled: true
|
||||
# 文件路径
|
||||
profile: D:/profile/
|
||||
# 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
|
||||
profile: D:/ruoyi/uploadPath
|
||||
# 获取ip地址开关
|
||||
addressEnabled: true
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ public class Global
|
|||
*/
|
||||
public static String getAvatarPath()
|
||||
{
|
||||
return getConfig("ruoyi.profile") + "avatar/";
|
||||
return getProfile() + "/avatar";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,7 +129,7 @@ public class Global
|
|||
*/
|
||||
public static String getDownloadPath()
|
||||
{
|
||||
return getConfig("ruoyi.profile") + "download/";
|
||||
return getProfile() + "/download";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,6 +137,6 @@ public class Global
|
|||
*/
|
||||
public static String getUploadPath()
|
||||
{
|
||||
return getConfig("ruoyi.profile") + "upload/";
|
||||
return getProfile() + "/upload";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,12 +113,7 @@ public class FileUploadUtils
|
|||
|
||||
File desc = getAbsoluteFile(baseDir, fileName);
|
||||
file.transferTo(desc);
|
||||
String pathFileName = baseDir + fileName;
|
||||
if (StringUtils.contains(baseDir, ":"))
|
||||
{
|
||||
// windows 去除盘符
|
||||
pathFileName = StringUtils.substringAfterLast(baseDir, ":") + fileName;
|
||||
}
|
||||
String pathFileName = getPathFileName(baseDir, fileName);
|
||||
return pathFileName;
|
||||
}
|
||||
|
||||
|
@ -127,15 +122,15 @@ public class FileUploadUtils
|
|||
*/
|
||||
public static final String extractFilename(MultipartFile file)
|
||||
{
|
||||
String filename = file.getOriginalFilename();
|
||||
String fileName = file.getOriginalFilename();
|
||||
String extension = getExtension(file);
|
||||
filename = DateUtils.datePath() + "/" + encodingFilename(filename) + "." + extension;
|
||||
return filename;
|
||||
fileName = DateUtils.datePath() + "/" + encodingFilename(fileName) + "." + extension;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
private static final File getAbsoluteFile(String uploadDir, String filename) throws IOException
|
||||
private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException
|
||||
{
|
||||
File desc = new File(uploadDir + File.separator + filename);
|
||||
File desc = new File(uploadDir + File.separator + fileName);
|
||||
|
||||
if (!desc.getParentFile().exists())
|
||||
{
|
||||
|
@ -148,14 +143,22 @@ public class FileUploadUtils
|
|||
return desc;
|
||||
}
|
||||
|
||||
private static final String getPathFileName(String uploadDir, String fileName) throws IOException
|
||||
{
|
||||
int dirLastIndex = uploadDir.lastIndexOf("/") + 1;
|
||||
String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
|
||||
String pathFileName = "/profile/" + currentDir + "/" + fileName;
|
||||
return pathFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编码文件名
|
||||
*/
|
||||
private static final String encodingFilename(String filename)
|
||||
private static final String encodingFilename(String fileName)
|
||||
{
|
||||
filename = filename.replace("_", " ");
|
||||
filename = Md5Utils.hash(filename + System.nanoTime() + counter++);
|
||||
return filename;
|
||||
fileName = fileName.replace("_", " ");
|
||||
fileName = Md5Utils.hash(fileName + System.nanoTime() + counter++);
|
||||
return fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,28 +178,28 @@ public class FileUploadUtils
|
|||
throw new FileSizeLimitExceededException(DEFAULT_MAX_SIZE / 1024 / 1024);
|
||||
}
|
||||
|
||||
String filename = file.getOriginalFilename();
|
||||
String fileName = file.getOriginalFilename();
|
||||
String extension = getExtension(file);
|
||||
if (allowedExtension != null && !isAllowedExtension(extension, allowedExtension))
|
||||
{
|
||||
if (allowedExtension == MimeTypeUtils.IMAGE_EXTENSION)
|
||||
{
|
||||
throw new InvalidExtensionException.InvalidImageExtensionException(allowedExtension, extension,
|
||||
filename);
|
||||
fileName);
|
||||
}
|
||||
else if (allowedExtension == MimeTypeUtils.FLASH_EXTENSION)
|
||||
{
|
||||
throw new InvalidExtensionException.InvalidFlashExtensionException(allowedExtension, extension,
|
||||
filename);
|
||||
fileName);
|
||||
}
|
||||
else if (allowedExtension == MimeTypeUtils.MEDIA_EXTENSION)
|
||||
{
|
||||
throw new InvalidExtensionException.InvalidMediaExtensionException(allowedExtension, extension,
|
||||
filename);
|
||||
fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidExtensionException(allowedExtension, extension, filename);
|
||||
throw new InvalidExtensionException(allowedExtension, extension, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@ public class ResourcesConfig implements WebMvcConfigurer
|
|||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry)
|
||||
{
|
||||
/** 文件上传路径 */
|
||||
registry.addResourceHandler("/profile/**").addResourceLocations("file:" + Global.getProfile());
|
||||
/** 本地文件上传路径 */
|
||||
registry.addResourceHandler("/profile/**").addResourceLocations("file:" + Global.getProfile() + "/");
|
||||
|
||||
/** swagger配置 */
|
||||
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||
|
|
Loading…
Reference in New Issue