Pre Merge pull request !173 from 让无线电飞BG8GLR/master
commit
0ac2ae8b35
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file
|
@ -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<String> 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())));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue