diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/FileController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/FileController.java index 6666b95..6270e92 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/FileController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/FileController.java @@ -58,6 +58,8 @@ public class FileController { private BaseCommonService baseCommonService; @Value(value = "${jeecg.appName}") private String applicationName; + @Value(value = "${jeecg.file-preview-download-domain:}") + private String filePreviewDownloadDomain; private static final String FILE_PREVIEW_REDIS_PREFIX = "sys:file:preview:"; private static final long FILE_PREVIEW_TOKEN_EXPIRE_SECONDS = 600L; @@ -619,7 +621,22 @@ public class FileController { private String buildPreviewDownloadUrl(HttpServletRequest request, String token, String fileName) { // kkFileView judges the preview handler by file suffix; stream APIs without suffix need fullfilename. - return buildRequestBaseUrl(request) + "/sys/file/previewDownload?token=" + token + "&fullfilename=" + encodeUrlParam(fileName); + return getPreviewDownloadBaseUrl(request) + "/sys/file/previewDownload?token=" + token + "&fullfilename=" + encodeUrlParam(fileName); + } + + private String getPreviewDownloadBaseUrl(HttpServletRequest request) { + if (!StringUtils.isEmpty(filePreviewDownloadDomain) && !StringUtils.isEmpty(filePreviewDownloadDomain.trim())) { + // kkFileView may run on another host, so its download address must not depend on proxy headers. + return trimTrailingSlash(filePreviewDownloadDomain.trim()); + } + return buildRequestBaseUrl(request); + } + + private String trimTrailingSlash(String value) { + while (value.endsWith("/")) { + value = value.substring(0, value.length() - 1); + } + return value; } private JSONObject parsePreviewInfo(Object cache) {