diff --git a/nxhs-service/src/main/java/cc/yunxi/service/impl/FileServiceImpl.java b/nxhs-service/src/main/java/cc/yunxi/service/impl/FileServiceImpl.java index 0692985..686a01a 100644 --- a/nxhs-service/src/main/java/cc/yunxi/service/impl/FileServiceImpl.java +++ b/nxhs-service/src/main/java/cc/yunxi/service/impl/FileServiceImpl.java @@ -126,17 +126,17 @@ public class FileServiceImpl extends ServiceImpl implements IF } // 生成md5文件名 String hashName = FileUtils.generateName(content, originalName); + // 确定上传路径 + String URI = basePath + fileStyleEnum.toString().toLowerCase() + "/" + hashName; + String fullPath = System.getProperty("user.dir") + URI; // 判断文件是否存在,如果存在直接返回 FileUploadRespVO uploadRespVO = new FileUploadRespVO(); File fileInfo = getFileInfoByHashVal(hashName); - if (fileInfo != null) { + if (fileInfo != null && FileUtil.exist(fullPath)) { uploadRespVO.setName(fileInfo.getFilename()); uploadRespVO.setUrl(fileInfo.getUrl()); uploadRespVO.setField(fileInfo.getHashVal()); } else { - // 确定上传路径 - String URI = basePath + fileStyleEnum.toString().toLowerCase() + "/" + hashName; - String fullPath = System.getProperty("user.dir") + URI; // 上传到文件存储位置 FileUtil.writeBytes(content, fullPath); uploadRespVO.setName(originalName);