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
d6fb61be
Commit
d6fb61be
authored
Sep 29, 2019
by
dqjdda
Browse files
Merge branch 'master' of github.com:elunez/eladmin into 2.3dev
parents
0a2ae87e
db1d6e4e
Changes
2
Hide whitespace changes
Inline
Side-by-side
eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
View file @
d6fb61be
...
...
@@ -8,6 +8,8 @@ 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
;
import
java.io.*
;
...
...
@@ -231,7 +233,12 @@ 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
];
}
public
static
void
checkSize
(
long
maxSize
,
long
size
)
{
if
(
size
>
(
maxSize
*
1024
*
1024
)){
throw
new
BadRequestException
(
"文件超出规定大小"
);
...
...
eladmin-tools/src/main/java/me/zhengjie/service/impl/LocalStorageServiceImpl.java
View file @
d6fb61be
...
...
@@ -63,7 +63,7 @@ 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
.
getFileType
(
suffix
);
String
type
=
FileUtil
.
getFileType
ByMimeType
(
suffix
);
File
file
=
FileUtil
.
upload
(
multipartFile
,
path
+
type
+
File
.
separator
);
try
{
name
=
StringUtils
.
isBlank
(
name
)
?
FileUtil
.
getFileNameNoEx
(
multipartFile
.
getOriginalFilename
())
:
name
;
...
...
@@ -115,4 +115,4 @@ public class LocalStorageServiceImpl implements LocalStorageService {
localStorageRepository
.
delete
(
storage
);
}
}
}
\ No newline at end of file
}
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