From 9ef217c33c06bcd6c3ba387b91b6cee765ae1a05 Mon Sep 17 00:00:00 2001 From: zhaojun1998 Date: Tue, 3 Dec 2019 22:42:38 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E5=AD=98=E5=82=A8=20BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/service/SystemConfigService.java | 3 +++ .../zhaojun/local/controller/LocalController.java | 14 ++++---------- .../im/zhaojun/local/service/LocalServiceImpl.java | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/im/zhaojun/common/service/SystemConfigService.java b/src/main/java/im/zhaojun/common/service/SystemConfigService.java index 11927bf..6a13137 100644 --- a/src/main/java/im/zhaojun/common/service/SystemConfigService.java +++ b/src/main/java/im/zhaojun/common/service/SystemConfigService.java @@ -48,6 +48,9 @@ public class SystemConfigService { case SystemConfigConstant.PASSWORD: systemConfigDTO.setPassword(systemConfig.getValue()); break; + case SystemConfigConstant.DOMAIN: + systemConfigDTO.setDomain(systemConfig.getValue()); + break; default:break; } } diff --git a/src/main/java/im/zhaojun/local/controller/LocalController.java b/src/main/java/im/zhaojun/local/controller/LocalController.java index eb923c0..70b92f2 100644 --- a/src/main/java/im/zhaojun/local/controller/LocalController.java +++ b/src/main/java/im/zhaojun/local/controller/LocalController.java @@ -17,7 +17,6 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.File; import java.io.IOException; -import java.nio.file.Files; import java.util.Date; @Controller @@ -39,18 +38,13 @@ public class LocalController { } private ResponseEntity export(File file) throws IOException { - // 获取文件 MIME 类型 - String fileMimeType = Files.probeContentType(file.toPath()); MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM; - HttpHeaders headers = new HttpHeaders(); - if (fileMimeType == null || "".equals(fileMimeType)) { - headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); - headers.add("Content-Disposition", "attachment; filename=" + file.getName()); - } else { - mediaType = MediaType.parseMediaType(fileMimeType); - } + HttpHeaders headers = new HttpHeaders(); + headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); + headers.setContentDispositionFormData("attachment", URLUtil.encode(file.getName())); + headers.add("Pragma", "no-cache"); headers.add("Expires", "0"); headers.add("Last-Modified", new Date().toString()); diff --git a/src/main/java/im/zhaojun/local/service/LocalServiceImpl.java b/src/main/java/im/zhaojun/local/service/LocalServiceImpl.java index 4edb767..3cd7242 100644 --- a/src/main/java/im/zhaojun/local/service/LocalServiceImpl.java +++ b/src/main/java/im/zhaojun/local/service/LocalServiceImpl.java @@ -84,7 +84,7 @@ public class LocalServiceImpl implements FileService { @Override public String getDownloadUrl(String path) throws Exception { SystemConfig usernameConfig = systemConfigRepository.findByKey(SystemConfigConstant.DOMAIN); - return StringUtils.concatPath( usernameConfig.getValue(), "file" + path); + return StringUtils.removeDuplicateSeparator(usernameConfig.getValue() + "/file/" + path); } public String getFilePath() {