Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
slm-fileview
Project
Project
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
jenkins
slm-fileview
Commits
2177aed6
Commit
2177aed6
authored
Aug 19, 2021
by
jerrykcode
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复: 文件名含有特殊字符时无法预览
parent
2395a489
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
FileHandlerService.java
...r/src/main/java/cn/keking/service/FileHandlerService.java
+1
-0
WebUtils.java
server/src/main/java/cn/keking/utils/WebUtils.java
+21
-0
No files found.
server/src/main/java/cn/keking/service/FileHandlerService.java
View file @
2177aed6
...
...
@@ -273,6 +273,7 @@ public class FileHandlerService {
attribute
.
setType
(
type
);
attribute
.
setName
(
fileName
);
attribute
.
setSuffix
(
suffix
);
url
=
WebUtils
.
encodeUrlFileName
(
url
);
attribute
.
setUrl
(
url
);
if
(
req
!=
null
)
{
String
officePreviewType
=
req
.
getParameter
(
"officePreviewType"
);
...
...
server/src/main/java/cn/keking/utils/WebUtils.java
View file @
2177aed6
...
...
@@ -2,8 +2,10 @@ package cn.keking.utils;
import
io.mola.galimatias.GalimatiasParseException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URLEncoder
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -97,4 +99,23 @@ public class WebUtils {
String
fileName
=
nonPramStr
.
substring
(
nonPramStr
.
lastIndexOf
(
"/"
)
+
1
);
return
KkFileUtils
.
suffixFromFileName
(
fileName
);
}
/**
* 对url中的文件名进行UTF-8编码
*
* @param url url
* @return 文件名编码后的url
*/
public
static
String
encodeUrlFileName
(
String
url
)
{
String
noQueryUrl
=
url
.
substring
(
0
,
url
.
contains
(
"?"
)
?
url
.
indexOf
(
"?"
)
:
url
.
length
());
int
fileNameStartIndex
=
noQueryUrl
.
lastIndexOf
(
'/'
)
+
1
;
int
fileNameEndIndex
=
noQueryUrl
.
lastIndexOf
(
'.'
);
String
encodedFileName
;
try
{
encodedFileName
=
URLEncoder
.
encode
(
noQueryUrl
.
substring
(
fileNameStartIndex
,
fileNameEndIndex
),
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
return
null
;
}
return
url
.
substring
(
0
,
fileNameStartIndex
)
+
encodedFileName
+
url
.
substring
(
fileNameEndIndex
);
}
}
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