From 552e7d4ad75b670377ed09a8f25c6e02e8c21623 Mon Sep 17 00:00:00 2001 From: "DESKTOP-TJ5DONV\\sky" Date: Mon, 22 Jul 2024 16:09:07 +0800 Subject: [PATCH 1/2] java.nio.file.NoSuchFileException: \opt\ocr\11\0d6969e22e6f4743b689592ddff138c8.jpg --- .../java/com/github/javpower/javavision/util/FileUtil.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/github/javpower/javavision/util/FileUtil.java b/src/main/java/com/github/javpower/javavision/util/FileUtil.java index cdb41ec..5b35f1c 100644 --- a/src/main/java/com/github/javpower/javavision/util/FileUtil.java +++ b/src/main/java/com/github/javpower/javavision/util/FileUtil.java @@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -25,6 +26,10 @@ public class FileUtil { // 获取文件后缀 String extension = FilenameUtils.getExtension(originalFileName); String target= UUID.fastUUID().toString().replace("-","")+"."+extension; + File parentFilePath=new File(fileProperties.getUploadPath()); + if(!parentFilePath.exists()){ + parentFilePath.mkdirs(); + } // 构建目标文件路径 Path targetLocation = Paths.get(fileProperties.getUploadPath()).resolve(target); // 将文件保存到目标路径 -- Gitee From db95e5d82d424ec0a81f427260a79faa8cc96c6c Mon Sep 17 00:00:00 2001 From: "DESKTOP-TJ5DONV\\sky" Date: Mon, 22 Jul 2024 16:26:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=89=BE=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E6=8C=87=E5=AE=9A=E7=9A=84=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../javavision/service/FaceService.java | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/github/javpower/javavision/service/FaceService.java b/src/main/java/com/github/javpower/javavision/service/FaceService.java index ef10dba..2a756b5 100644 --- a/src/main/java/com/github/javpower/javavision/service/FaceService.java +++ b/src/main/java/com/github/javpower/javavision/service/FaceService.java @@ -16,6 +16,7 @@ import com.github.javpower.javavision.entity.FaceParam; import com.github.javpower.javavision.entity.PersonObject; import com.github.javpower.javavision.util.FaceDetectUtil; import com.github.javpower.javavision.util.FaceSimilarityCalculator; +import com.github.javpower.javavision.util.FileUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; @@ -39,6 +40,8 @@ public class FaceService { @Autowired private FileProperties fileProperties; + @Autowired + private FileUtil fileUtil; public String addFace(FaceParam param, MultipartFile file, HttpServletRequest request) throws IOException, TranslateException, ModelNotFoundException, MalformedModelException, OrtException { List allJson = getAllJson(); if(CollectionUtil.isNotEmpty(allJson)){ @@ -109,25 +112,26 @@ public class FaceService { return false; } public String getPath(MultipartFile file) throws IOException { - String originalFilename = file.getOriginalFilename(); - log.info("originalFilename:" + originalFilename); - // 获取文件后缀 - String extension = FilenameUtils.getExtension(originalFilename); - String newFileName = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN) + RandomStringUtils.randomNumeric(6) + "." + extension; - log.info("newFileName:" + newFileName); - // 本地文件上传路径 - String uploadPath = fileProperties.getUploadPath(); - File uploadDir = new File(uploadPath); - // 上传目录不存在,则直接创建 - if (!uploadDir.exists()) { - uploadDir.mkdirs(); - } - // 上传文件到本地目录 - File uploadFile = new File(uploadDir, newFileName); - log.info("uploadFile:" + uploadFile); - file.transferTo(uploadFile); - String imgPath = uploadPath+newFileName; - return imgPath; +// String originalFilename = file.getOriginalFilename(); +// log.info("originalFilename:" + originalFilename); +// // 获取文件后缀 +// String extension = FilenameUtils.getExtension(originalFilename); +// String newFileName = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN) + RandomStringUtils.randomNumeric(6) + "." + extension; +// log.info("newFileName:" + newFileName); +// // 本地文件上传路径 +// String uploadPath = fileProperties.getUploadPath(); +// File uploadDir = new File(uploadPath); +// // 上传目录不存在,则直接创建 +// if (!uploadDir.exists()) { +// uploadDir.mkdirs(); +// } +// // 上传文件到本地目录 +// File uploadFile = new File(uploadDir, newFileName); +// log.info("uploadFile:" + uploadFile); +// file.transferTo(uploadFile); +// String imgPath = uploadPath+newFileName; +// return imgPath; + return fileUtil.getPath(file); } public void addJsonFile(FaceParam param){ -- Gitee