文件上传的逻辑Bug
来源:5-3 LinCMS内置文件上传系统演示
luckystar728
2020-11-01 14:04:12
# 文件上传的逻辑Bug
项目里在预处理器preHandler.handle里做了存库的操作,preHandler.handle的执行先于handleOneFile,而handleOneFile可能处理失败了返回false,但数据库插入成功了,返回给前端数据却是正确的结果(在preHandle里已经提前把数据add了),但是文件并没有真正上传成功,url也是无法访问的。
private void handleOneFile0(List<File> res, long singleFileLimit, MultipartFile file) {
byte[] bytes = getFileBytes(file);
String[] include = getFileProperties().getInclude();
String[] exclude = getFileProperties().getExclude();
String ext = checkOneFile(include, exclude, singleFileLimit, file.getOriginalFilename(), bytes.length);
String newFilename = getNewFilename(ext);
String storePath = getStorePath(newFilename);
// 生成文件的md5值
String md5 = FileUtil.getFileMD5(bytes);
File fileData = File.builder().
name(newFilename).
md5(md5).
key(file.getName()).
path(storePath).
size(bytes.length).
type(getFileType()).
extension(ext).
build();
// 如果预处理器不为空,且处理结果为false,直接返回, 否则处理
if (preHandler != null && !preHandler.handle(fileData)) {
return;
}
boolean ok = handleOneFile(bytes, newFilename);
if (ok) {
res.add(fileData);
}
}
1回答
麻烦再github上提一个issue,会有专人处理。
谢谢了