文档库--上传文件限制

This commit is contained in:
zhn
2022-03-23 22:28:41 +08:00
parent c27d401ddf
commit c089041fb1
4 changed files with 29 additions and 5 deletions
@@ -17,7 +17,7 @@ public interface IOSSFileService extends IService<OSSFile> {
* @param bizPath 自定义路径
* @return
*/
public OSSFile uploadLocal(MultipartFile mf, String bizPath);
public OSSFile uploadLocal(MultipartFile mf, String bizPath,String state);
public List<OSSFile> getFileInfos(String id);
@@ -30,6 +30,12 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
@Value(value = "${jero.path.upload}")
private String uploadpath;
/**
* 文件后缀黑名单
*/
@Value(value="${jero.fileSuffixLimits}")
private String[] fileSuffixLimits;
@Override
public void upload(MultipartFile multipartFile) throws IOException {
String fileName = multipartFile.getOriginalFilename();
@@ -51,7 +57,7 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
* @return
*/
@Override
public OSSFile uploadLocal(MultipartFile mf, String bizPath) {
public OSSFile uploadLocal(MultipartFile mf, String bizPath,String state) {
//处理文件大小,大于100M抛出异常
long fileSize = mf.getSize() / 1024 / 1024;
@@ -78,7 +84,19 @@ public class OSSFileServiceImpl extends ServiceImpl<OSSFileMapper, OSSFile> impl
}
fileType = orgName.substring(orgName.lastIndexOf("."));
String fileTypeStr = ".doc,.DOC,.docx,.DOCX,.xls, .XLS,.xlsx,.XLSX,.pdf,.PDF";
//判断文件类型
if("0".equals(state)){
//固定文件
if(!fileTypeStr.contains(fileType)){
throw new JeroBootException("只能够上传pdf,word,excel类型的文件。请重新选择文件!");
}
}else{
if (CommonUtils.limitFileSuffix(orgName, fileSuffixLimits)) {
throw new JeroBootException("不能上传"+StringUtils.join(fileSuffixLimits, ",")+"类型的文件。请重新选择文件!");
}
}
if (StringUtils.isNotEmpty(fileType)) {
String[] fileTypeArr = {".doc",".DOC",".txt",".TXT", ".docx",".DOCX",
".xls", ".XLS",".xlsx",".XLSX", ".pdf",".PDF", ".png",".PNG",
@@ -137,7 +137,7 @@ public class CommonController {
*/
@ApiOperation(value="文件上传统一方法", notes="文件上传统一方法")
@PostMapping(value = "/upload")
public Result<?> upload(HttpServletRequest request, HttpServletResponse response) {
public Result<?> upload(HttpServletRequest request, HttpServletResponse response,String state) {
Result<OSSFile> result = new Result<>();
String bizPath = request.getParameter("biz");
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
@@ -150,7 +150,7 @@ public class CommonController {
bizPath = "";
}
}
OSSFile oSSFile = ossFileService.uploadLocal(file, bizPath);
OSSFile oSSFile = ossFileService.uploadLocal(file, bizPath,state);
if (oConvertUtils.isNotEmpty(oSSFile)) {
result.setResult(oSSFile);
result.setSuccess(true);