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
10dcf6e1
Commit
10dcf6e1
authored
Jun 07, 2021
by
Zheng Jie
Browse files
[Bug修复](master): 头像上传验证图片格式,限制图片大小
close
https://github.com/elunez/eladmin/issues/642
parent
923142bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
View file @
10dcf6e1
...
@@ -17,6 +17,7 @@ package me.zhengjie.modules.system.service.impl;
...
@@ -17,6 +17,7 @@ package me.zhengjie.modules.system.service.impl;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
me.zhengjie.config.FileProperties
;
import
me.zhengjie.config.FileProperties
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.modules.security.service.OnlineUserService
;
import
me.zhengjie.modules.security.service.OnlineUserService
;
import
me.zhengjie.modules.security.service.UserCacheClean
;
import
me.zhengjie.modules.security.service.UserCacheClean
;
import
me.zhengjie.modules.system.domain.User
;
import
me.zhengjie.modules.system.domain.User
;
...
@@ -184,6 +185,14 @@ public class UserServiceImpl implements UserService {
...
@@ -184,6 +185,14 @@ public class UserServiceImpl implements UserService {
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Map
<
String
,
String
>
updateAvatar
(
MultipartFile
multipartFile
)
{
public
Map
<
String
,
String
>
updateAvatar
(
MultipartFile
multipartFile
)
{
// 文件大小验证
FileUtil
.
checkSize
(
properties
.
getAvatarMaxSize
(),
multipartFile
.
getSize
());
// 验证文件上传的格式
String
image
=
"gif jpg png jpeg"
;
String
fileType
=
FileUtil
.
getExtensionName
(
multipartFile
.
getOriginalFilename
());
if
(
fileType
!=
null
&&
!
image
.
contains
(
fileType
)){
throw
new
BadRequestException
(
"文件格式错误!, 仅支持 "
+
image
+
" 格式"
);
}
User
user
=
userRepository
.
findByUsername
(
SecurityUtils
.
getCurrentUsername
());
User
user
=
userRepository
.
findByUsername
(
SecurityUtils
.
getCurrentUsername
());
String
oldPath
=
user
.
getAvatarPath
();
String
oldPath
=
user
.
getAvatarPath
();
File
file
=
FileUtil
.
upload
(
multipartFile
,
properties
.
getPath
().
getAvatar
());
File
file
=
FileUtil
.
upload
(
multipartFile
,
properties
.
getPath
().
getAvatar
());
...
...
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