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