From 4580bcf8e058c18beed5539e2c6642f74dc385ec Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 17 Aug 2025 15:52:53 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E3=80=90infra=20=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E8=AE=BE=E6=96=BD=E3=80=91LocalFileClient=20=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E4=B8=8D=E5=88=B0=E6=96=87=E4=BB=B6=EF=BC=88getContent?= =?UTF-8?q?=EF=BC=89=E6=97=B6=EF=BC=8C=E8=BF=94=E5=9B=9E=20null=20?= =?UTF-8?q?=E8=80=8C=E4=B8=8D=E6=98=AF=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=20https://github.com/YunaiV/ruoyi-vue-pro/issues/929?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/core/client/local/LocalFileClient.java | 10 +++++++++- .../file/core/local/LocalFileClientTest.java | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/local/LocalFileClient.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/local/LocalFileClient.java index 7fa2a7ea9a..6e5c0229ba 100644 --- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/local/LocalFileClient.java +++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/local/LocalFileClient.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.infra.framework.file.core.client.local; import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.IORuntimeException; import cn.iocoder.yudao.module.infra.framework.file.core.client.AbstractFileClient; import java.io.File; @@ -38,7 +39,14 @@ public class LocalFileClient extends AbstractFileClient { @Override public byte[] getContent(String path) { String filePath = getFilePath(path); - return FileUtil.readBytes(filePath); + try { + return FileUtil.readBytes(filePath); + } catch (IORuntimeException ex) { + if (ex.getMessage().startsWith("File not exist:")) { + return null; + } + throw ex; + } } private String getFilePath(String path) { diff --git a/yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/framework/file/core/local/LocalFileClientTest.java b/yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/framework/file/core/local/LocalFileClientTest.java index 7c622a5306..6bc8c7bfe9 100644 --- a/yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/framework/file/core/local/LocalFileClientTest.java +++ b/yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/framework/file/core/local/LocalFileClientTest.java @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.infra.framework.file.core.client.local.LocalFileC import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; + public class LocalFileClientTest { @Test @@ -26,4 +28,18 @@ public class LocalFileClientTest { client.delete(path); } + @Test + @Disabled + public void testGetContent_notFound() { + // 创建客户端 + LocalFileClientConfig config = new LocalFileClientConfig(); + config.setDomain("http://127.0.0.1:48080"); + config.setBasePath("/Users/yunai/file_test"); + LocalFileClient client = new LocalFileClient(0L, config); + client.init(); + // 上传文件 + byte[] content = client.getContent(randomString()); + System.out.println(); + } + }