Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
roncoo
roncoo-education
提交
bedef726
R
roncoo-education
项目概览
roncoo
/
roncoo-education
大约 1 年 前同步成功
通知
146
Star
5
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roncoo-education
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bedef726
编写于
5月 04, 2023
作者:
F
fengyw
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bug修复,对上传的图片进行类型限制
上级
5023b919
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
47 addition
and
8 deletion
+47
-8
roncoo-education-common/roncoo-education-common-core/src/main/java/com/roncoo/education/common/core/tools/FileUtils.java
...ava/com/roncoo/education/common/core/tools/FileUtils.java
+35
-0
roncoo-education-system/roncoo-education-system-service/src/main/java/com/roncoo/education/system/service/admin/AdminUploadController.java
...education/system/service/admin/AdminUploadController.java
+2
-2
roncoo-education-system/roncoo-education-system-service/src/main/java/com/roncoo/education/system/service/auth/AuthUploadController.java
...o/education/system/service/auth/AuthUploadController.java
+2
-2
roncoo-education-system/roncoo-education-system-service/src/main/java/com/roncoo/education/system/service/biz/UploadCommonBiz.java
.../roncoo/education/system/service/biz/UploadCommonBiz.java
+8
-4
未找到文件。
roncoo-education-common/roncoo-education-common-core/src/main/java/com/roncoo/education/common/core/tools/FileUtils.java
0 → 100644
浏览文件 @
bedef726
/**
* Copyright 2015-现在 广州市领课网络科技有限公司
*/
package
com.roncoo.education.common.core.tools
;
import
cn.hutool.core.io.FileTypeUtil
;
import
cn.hutool.core.util.StrUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
/**
* 判断文件类型
*
* @author fengyw
*/
@Slf4j
public
final
class
FileUtils
{
private
static
final
String
PIC_TYPE_MAP
=
"jpg|png|gif|bmp|webp"
;
private
FileUtils
()
{
}
public
static
boolean
isPic
(
MultipartFile
file
)
{
try
{
String
fileType
=
FileTypeUtil
.
getType
(
file
.
getInputStream
());
return
StrUtil
.
isNotBlank
(
fileType
)
&&
PIC_TYPE_MAP
.
contains
(
fileType
);
}
catch
(
IOException
e
)
{
log
.
error
(
"判断文件类型错误"
,
e
);
return
false
;
}
}
}
roncoo-education-system/roncoo-education-system-service/src/main/java/com/roncoo/education/system/service/admin/AdminUploadController.java
浏览文件 @
bedef726
...
...
@@ -2,7 +2,7 @@ package com.roncoo.education.system.service.admin;
import
com.roncoo.education.common.core.base.Result
;
import
com.roncoo.education.common.service.BaseController
;
import
com.roncoo.education.system.service.
admin.biz.AdminUpload
Biz
;
import
com.roncoo.education.system.service.
biz.UploadCommon
Biz
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
...
...
@@ -26,7 +26,7 @@ import java.io.File;
public
class
AdminUploadController
extends
BaseController
{
@Autowired
private
AdminUpload
Biz
biz
;
private
UploadCommon
Biz
biz
;
@ApiOperation
(
value
=
"上传图片"
,
notes
=
"服务端上传图片接口,只支持图片格式"
)
@ApiImplicitParam
(
name
=
"picFile"
,
value
=
"图片文件"
,
dataType
=
"File"
,
dataTypeClass
=
File
.
class
,
paramType
=
"query"
,
required
=
true
)
...
...
roncoo-education-system/roncoo-education-system-service/src/main/java/com/roncoo/education/system/service/auth/AuthUploadController.java
浏览文件 @
bedef726
...
...
@@ -2,7 +2,7 @@ package com.roncoo.education.system.service.auth;
import
com.roncoo.education.common.core.base.Result
;
import
com.roncoo.education.common.service.BaseController
;
import
com.roncoo.education.system.service.
admin.biz.AdminUpload
Biz
;
import
com.roncoo.education.system.service.
biz.UploadCommon
Biz
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
...
...
@@ -26,7 +26,7 @@ import java.io.File;
public
class
AuthUploadController
extends
BaseController
{
@Autowired
private
AdminUpload
Biz
biz
;
private
UploadCommon
Biz
biz
;
@ApiOperation
(
value
=
"上传图片"
,
notes
=
"服务端上传图片接口,只支持图片格式"
)
@ApiImplicitParam
(
name
=
"picFile"
,
value
=
"图片文件"
,
dataType
=
"File"
,
dataTypeClass
=
File
.
class
,
paramType
=
"query"
,
required
=
true
)
...
...
roncoo-education-system/roncoo-education-system-service/src/main/java/com/roncoo/education/system/service/
admin/biz/AdminUpload
Biz.java
→
roncoo-education-system/roncoo-education-system-service/src/main/java/com/roncoo/education/system/service/
biz/UploadCommon
Biz.java
浏览文件 @
bedef726
/**
* Copyright 2015-现在 广州市领课网络科技有限公司
*/
package
com.roncoo.education.system.service.
admin.
biz
;
package
com.roncoo.education.system.service.biz
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.roncoo.education.common.core.base.Result
;
import
com.roncoo.education.common.core.enums.StoragePlatformEnum
;
import
com.roncoo.education.common.core.tools.FileUtils
;
import
com.roncoo.education.common.upload.Upload
;
import
com.roncoo.education.common.upload.UploadFace
;
import
com.roncoo.education.system.service.biz.SysConfigCommonBiz
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
...
...
@@ -24,7 +24,7 @@ import java.util.Map;
*/
@Slf4j
@Component
public
class
AdminUpload
Biz
{
public
class
UploadCommon
Biz
{
@Autowired
private
Map
<
String
,
UploadFace
>
uploadFaceMap
;
...
...
@@ -33,13 +33,17 @@ public class AdminUploadBiz {
private
SysConfigCommonBiz
sysConfigCommonBiz
;
public
Result
<
String
>
uploadPic
(
MultipartFile
picFile
)
{
if
(!
FileUtils
.
isPic
(
picFile
))
{
return
Result
.
error
(
"请选择图片上传"
);
}
Upload
upload
=
sysConfigCommonBiz
.
getSysConfig
(
Upload
.
class
);
if
(
ObjectUtil
.
isNotEmpty
(
upload
)
||
StringUtils
.
isEmpty
(
upload
.
getStoragePlatform
()))
{
UploadFace
uploadFace
=
uploadFaceMap
.
get
(
StoragePlatformEnum
.
byCode
(
Integer
.
valueOf
(
upload
.
getStoragePlatform
())).
getMode
());
String
fileUrl
=
uploadFace
.
uploadPic
(
picFile
,
upload
);
return
Result
.
success
(
fileUrl
);
}
return
Result
.
error
(
"上传参数配置"
);
return
Result
.
error
(
"上传参数
没
配置"
);
}
public
Result
<
String
>
uploadDoc
(
MultipartFile
docFile
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录