From ea234abf4660329d904c4409ea57dd561aeb76e8 Mon Sep 17 00:00:00 2001 From: maning <3297813122@qq.com> Date: Thu, 24 Oct 2024 15:54:58 +0800 Subject: [PATCH] =?UTF-8?q?fix-fileServer-=E4=BF=AE=E5=A4=8Dget=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E6=96=87=E4=BB=B6=E5=90=8D=E5=86=B2=E7=AA=81=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=97=A0=E6=B3=95=E8=8E=B7=E5=8F=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/ximatai/muyun/fileserver/FileServer.java | 2 +- .../net/ximatai/muyun/fileserver/FileService.java | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/muyun-fileserver/src/main/java/net/ximatai/muyun/fileserver/FileServer.java b/muyun-fileserver/src/main/java/net/ximatai/muyun/fileserver/FileServer.java index 5e4ec1dd..bfca1824 100644 --- a/muyun-fileserver/src/main/java/net/ximatai/muyun/fileserver/FileServer.java +++ b/muyun-fileserver/src/main/java/net/ximatai/muyun/fileserver/FileServer.java @@ -107,7 +107,7 @@ private void download(RoutingContext ctx) { ctx.response() .putHeader("Content-Disposition", "attachment; filename=" + content) .sendFile(fileObtained.getPath()); - vertx.fileSystem().delete(fileObtained.getPath()); + // vertx.fileSystem().delete(fileObtained.getPath()); } } else { logger.error("Failed to read file name: " + result.cause()); diff --git a/muyun-fileserver/src/main/java/net/ximatai/muyun/fileserver/FileService.java b/muyun-fileserver/src/main/java/net/ximatai/muyun/fileserver/FileService.java index f03a6a23..fbabed02 100644 --- a/muyun-fileserver/src/main/java/net/ximatai/muyun/fileserver/FileService.java +++ b/muyun-fileserver/src/main/java/net/ximatai/muyun/fileserver/FileService.java @@ -124,16 +124,14 @@ public File get(String id) { try { String name = Files.readString(pathN); byte[] bytes = Files.readAllBytes(pathO); - String fileBak = getUploadPath() + name; - File newFile = new File(fileBak); - if (newFile.createNewFile()) { - Files.write(Paths.get(fileBak), bytes); - return newFile; - } + // 上传文件副本 + File newFile = File.createTempFile(name.split("\\.")[0], "." + name.split("\\.")[1]); + Files.write(Paths.get(newFile.getPath()), bytes); + return newFile; } catch (IOException e) { throw new RuntimeException(e); } - return null; + // return null; } // 丢弃服务器端中的文件