From 2d81e405b88562d1a2d49ec5f1afad76355ba9af Mon Sep 17 00:00:00 2001 From: zhengyouxiancq Date: Tue, 4 Mar 2025 15:42:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=90=E5=88=B6=E9=BB=98=E8=AE=A4=E5=8F=AA?= =?UTF-8?q?=E8=83=BD=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87,=E5=8F=AF?= =?UTF-8?q?=E8=87=AA=E8=A1=8C=E4=BF=AE=E6=94=B9=E6=88=96=E5=88=A0=E9=99=A4?= =?UTF-8?q?,=E8=A7=A3=E5=86=B3=E5=95=86=E7=94=A8=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infra/controller/admin/file/FileController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java index db137d5ed..2df259741 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java @@ -24,6 +24,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.module.infra.framework.file.core.utils.FileTypeUtils.writeAttachment; @@ -42,6 +43,14 @@ public class FileController { public CommonResult uploadFile(FileUploadReqVO uploadReqVO) throws Exception { MultipartFile file = uploadReqVO.getFile(); String path = uploadReqVO.getPath(); + // 校验文件类型 + String extname = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")).toLowerCase(); + if(StrUtil.isEmpty(extname)){ + return error(3379,"只能上传图片文件!"); + } + if(!".bmp,.jpg,.jpeg,.png".contains(extname)) { + return error(3379,"只能上传图片文件!"); + } return success(fileService.createFile(file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream()))); }