Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
78f08353
Commit
78f08353
authored
Sep 29, 2019
by
dqjdda
Browse files
2.3 代码优化
parent
d6fb61be
Changes
2
Hide whitespace changes
Inline
Side-by-side
eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
View file @
78f08353
...
...
@@ -5,10 +5,8 @@ import cn.hutool.core.io.IoUtil;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.poi.excel.BigExcelWriter
;
import
cn.hutool.poi.excel.ExcelUtil
;
import
cn.hutool.poi.excel.ExcelWriter
;
import
me.zhengjie.exception.BadRequestException
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.activation.MimetypesFileTypeMap
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
...
...
@@ -233,11 +231,10 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
return
"视频"
;
}
else
return
"其他"
;
}
public
static
String
getFileTypeByMimeType
(
String
type
)
{
// URLConnection.guessContentTypeFromName("." + type)
// way 2 new MimetypesFileTypeMap().getContentType("."+ "txt")
String
mimeType
=
new
MimetypesFileTypeMap
().
getContentType
(
"."
+
type
);
return
mimeType
.
split
(
"\\/"
)[
0
];
return
mimeType
.
split
(
"\\/"
)[
0
];
}
public
static
void
checkSize
(
long
maxSize
,
long
size
)
{
if
(
size
>
(
maxSize
*
1024
*
1024
)){
...
...
eladmin-tools/src/main/java/me/zhengjie/service/impl/LocalStorageServiceImpl.java
View file @
78f08353
...
...
@@ -63,7 +63,9 @@ public class LocalStorageServiceImpl implements LocalStorageService {
public
LocalStorageDTO
create
(
String
name
,
MultipartFile
multipartFile
)
{
FileUtil
.
checkSize
(
maxSize
,
multipartFile
.
getSize
());
String
suffix
=
FileUtil
.
getExtensionName
(
multipartFile
.
getOriginalFilename
());
String
type
=
FileUtil
.
getFileTypeByMimeType
(
suffix
);
// 可自行选择方式
// String type = FileUtil.getFileTypeByMimeType(suffix);
String
type
=
FileUtil
.
getFileType
(
suffix
);
File
file
=
FileUtil
.
upload
(
multipartFile
,
path
+
type
+
File
.
separator
);
try
{
name
=
StringUtils
.
isBlank
(
name
)
?
FileUtil
.
getFileNameNoEx
(
multipartFile
.
getOriginalFilename
())
:
name
;
...
...
Write
Preview
Supports
Markdown
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