Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fgqyxxlr
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yaru
fgqyxxlr
Commits
dcd6f225
Commit
dcd6f225
authored
Jul 17, 2019
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件路径更换
parent
7922cabb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
27 deletions
+30
-27
ruoyi-admin/src/main/resources/application.yml
+2
-2
ruoyi-common/src/main/java/com/ruoyi/common/config/Global.java
+3
-3
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java
+23
-20
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java
+2
-2
No files found.
ruoyi-admin/src/main/resources/application.yml
View file @
dcd6f225
...
...
@@ -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
...
...
ruoyi-common/src/main/java/com/ruoyi/common/config/Global.java
View file @
dcd6f225
...
...
@@ -121,7 +121,7 @@ public class Global
*/
public
static
String
getAvatarPath
()
{
return
get
Config
(
"ruoyi.profile"
)
+
"avatar/
"
;
return
get
Profile
()
+
"/avatar
"
;
}
/**
...
...
@@ -129,7 +129,7 @@ public class Global
*/
public
static
String
getDownloadPath
()
{
return
get
Config
(
"ruoyi.profile"
)
+
"download/
"
;
return
get
Profile
()
+
"/download
"
;
}
/**
...
...
@@ -137,6 +137,6 @@ public class Global
*/
public
static
String
getUploadPath
()
{
return
get
Config
(
"ruoyi.profile"
)
+
"upload/
"
;
return
get
Profile
()
+
"/upload
"
;
}
}
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java
View file @
dcd6f225
...
...
@@ -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
file
n
ame
=
file
.
getOriginalFilename
();
String
file
N
ame
=
file
.
getOriginalFilename
();
String
extension
=
getExtension
(
file
);
file
name
=
DateUtils
.
datePath
()
+
"/"
+
encodingFilename
(
filen
ame
)
+
"."
+
extension
;
return
file
n
ame
;
file
Name
=
DateUtils
.
datePath
()
+
"/"
+
encodingFilename
(
fileN
ame
)
+
"."
+
extension
;
return
file
N
ame
;
}
private
static
final
File
getAbsoluteFile
(
String
uploadDir
,
String
file
n
ame
)
throws
IOException
private
static
final
File
getAbsoluteFile
(
String
uploadDir
,
String
file
N
ame
)
throws
IOException
{
File
desc
=
new
File
(
uploadDir
+
File
.
separator
+
file
n
ame
);
File
desc
=
new
File
(
uploadDir
+
File
.
separator
+
file
N
ame
);
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
file
n
ame
)
private
static
final
String
encodingFilename
(
String
file
N
ame
)
{
file
name
=
filen
ame
.
replace
(
"_"
,
" "
);
file
name
=
Md5Utils
.
hash
(
filen
ame
+
System
.
nanoTime
()
+
counter
++);
return
file
n
ame
;
file
Name
=
fileN
ame
.
replace
(
"_"
,
" "
);
file
Name
=
Md5Utils
.
hash
(
fileN
ame
+
System
.
nanoTime
()
+
counter
++);
return
file
N
ame
;
}
/**
...
...
@@ -175,28 +178,28 @@ public class FileUploadUtils
throw
new
FileSizeLimitExceededException
(
DEFAULT_MAX_SIZE
/
1024
/
1024
);
}
String
file
n
ame
=
file
.
getOriginalFilename
();
String
file
N
ame
=
file
.
getOriginalFilename
();
String
extension
=
getExtension
(
file
);
if
(
allowedExtension
!=
null
&&
!
isAllowedExtension
(
extension
,
allowedExtension
))
{
if
(
allowedExtension
==
MimeTypeUtils
.
IMAGE_EXTENSION
)
{
throw
new
InvalidExtensionException
.
InvalidImageExtensionException
(
allowedExtension
,
extension
,
file
n
ame
);
file
N
ame
);
}
else
if
(
allowedExtension
==
MimeTypeUtils
.
FLASH_EXTENSION
)
{
throw
new
InvalidExtensionException
.
InvalidFlashExtensionException
(
allowedExtension
,
extension
,
file
n
ame
);
file
N
ame
);
}
else
if
(
allowedExtension
==
MimeTypeUtils
.
MEDIA_EXTENSION
)
{
throw
new
InvalidExtensionException
.
InvalidMediaExtensionException
(
allowedExtension
,
extension
,
file
n
ame
);
file
N
ame
);
}
else
{
throw
new
InvalidExtensionException
(
allowedExtension
,
extension
,
file
n
ame
);
throw
new
InvalidExtensionException
(
allowedExtension
,
extension
,
file
N
ame
);
}
}
...
...
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java
View file @
dcd6f225
...
...
@@ -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/"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment