From 90403f17b6be4d5f75d62a22d20929feef0e4d2c Mon Sep 17 00:00:00 2001 From: wangchengjun <616865598@qq.com> Date: Wed, 15 Jun 2022 16:29:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=96=87=E4=BB=B6=E6=B5=81?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oss/controller/SplitFileController.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/oss/controller/SplitFileController.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/oss/controller/SplitFileController.java index 0ff91553f..c348af414 100644 --- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/oss/controller/SplitFileController.java +++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/oss/controller/SplitFileController.java @@ -43,25 +43,24 @@ public class SplitFileController { splitIndex = fileUrl.lastIndexOf("/"); } String fileName = fileUrl.substring(splitIndex + 1); +// response.setHeader("Content-Disposition", +// "attachment; filename=\""+fileName+"\""); response.setHeader("Content-Disposition", - "attachment; filename=\""+fileName+"\""); - response.setHeader("Content-Disposition", - "attachment; filename=\""+ SplitFileUtils.encodeFileName(fileName, request) +"\""); + "attachment; filename=\"" + SplitFileUtils.encodeFileName(fileName, request) + "\""); response.setContentType("application/force-download"); - try(OutputStream os = response.getOutputStream(); - /*FileInputStream fis = new FileInputStream(fileUrl);*/) { - if (CosBootUtil.doesObjectExist(fileUrl)) { - InputStream fis = CosBootUtil.download(fileUrl); + if (CosBootUtil.doesObjectExist(fileUrl)) { + try (OutputStream os = response.getOutputStream(); + InputStream fis = CosBootUtil.download(fileUrl)) { int len = 0; while ((len = fis.read()) != -1) { os.write(len); } os.flush(); + } catch (FileNotFoundException e) { + throw new JeroBootException("文件不存在"); + } catch (IOException e) { + throw new JeroBootException("文件不存在"); } - } catch (FileNotFoundException e) { - throw new JeroBootException("文件不存在"); - } catch (IOException e) { - throw new JeroBootException("文件不存在"); } }