java web项目文件上传中常见的mime类型(基于Apache的tika)
2021-02-03 10:19
标签:log slides template 文件 上传 star ali jpeg proc java代码 校验代码 java web项目文件上传中常见的mime类型(基于Apache的tika) 标签:log slides template 文件 上传 star ali jpeg proc 原文地址:https://www.cnblogs.com/passedbylove/p/12801686.html final Tika tika = new Tika();
Set
@RequestMapping(value = "start", method = RequestMethod.POST)
@ResponseBody
public String start(@Valid Project project, @RequestParam("prjInfoFile") MultipartFile prjInfoFile,
@RequestParam("prjDesignFile") MultipartFile prjDesignFile, @RequestParam("prjFinanceFile") MultipartFile prjFinanceFile,
@RequestParam("files") MultipartFile[] files, Model model) throws IOException {
byte[] byteInfoFile = prjInfoFile.getBytes();
if (byteInfoFile.length > 0) {
String filename = prjInfoFile.getOriginalFilename().toLowerCase();
String mimeType = tika.detect(byteInfoFile);
log.info("文件类型:{}", mimeType);
if (!(allowMimeType.contains(mimeType) || filename.endsWith(".pdf"))) {
return "error:【项目情况表】服务器暂不接受此类型的附件。".concat(allowExtension);
}
}
}
文章标题:java web项目文件上传中常见的mime类型(基于Apache的tika)
文章链接:http://soscw.com/index.php/essay/50380.html