diff --git a/laws-modules-docking/src/main/java/com/jero/modules/docking/download/service/impl/DownloadDecryptFileServiceImpl.java b/laws-modules-docking/src/main/java/com/jero/modules/docking/download/service/impl/DownloadDecryptFileServiceImpl.java index f25ba46d..66bc2c03 100644 --- a/laws-modules-docking/src/main/java/com/jero/modules/docking/download/service/impl/DownloadDecryptFileServiceImpl.java +++ b/laws-modules-docking/src/main/java/com/jero/modules/docking/download/service/impl/DownloadDecryptFileServiceImpl.java @@ -5,6 +5,7 @@ import com.jero.common.exception.JeroBootException; import com.jero.common.system.vo.LoginUser; import com.jero.modules.docking.download.service.DownloadDecryptFileService; import com.jero.modules.docking.utils.IntekeyUtils; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -158,7 +159,8 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic String fileName = ""; String headerField = response.getHeader("Content-Disposition"); - if (!StringUtils.isBlank(headerField) || headerField.contains("fileName=") || headerField.contains("filename=")){ + if (headerField != null && + (!StringUtils.isBlank(headerField) || headerField.contains("fileName=") || headerField.contains("filename="))){ String name = ""; if(headerField.contains("fileName=")){ name = "fileName"; @@ -166,6 +168,9 @@ public class DownloadDecryptFileServiceImpl implements DownloadDecryptFileServic name = "filename"; } fileName = headerField.substring(headerField.lastIndexOf(name + "=") + 9); + if (headerField.contains("filename*=UTF-8")){ + fileName = headerField.substring(headerField.lastIndexOf("filename*=UTF-8") + 17); + } }else { fileName = UUID.randomUUID().toString(); } diff --git a/laws-modules-docking/src/main/java/com/jero/modules/docking/utils/IntekeyUtils.java b/laws-modules-docking/src/main/java/com/jero/modules/docking/utils/IntekeyUtils.java index cedbdd2f..8078897a 100644 --- a/laws-modules-docking/src/main/java/com/jero/modules/docking/utils/IntekeyUtils.java +++ b/laws-modules-docking/src/main/java/com/jero/modules/docking/utils/IntekeyUtils.java @@ -1,6 +1,7 @@ package com.jero.modules.docking.utils; +import cn.hutool.core.util.StrUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.FileSystemResource; @@ -68,6 +69,10 @@ public class IntekeyUtils { File file = null; try { String originalFilename = multipartFile.getOriginalFilename(); + // 如果文件名中有特殊字符,则需要使用URLDecoder解析真正的文件名 + if (StrUtil.isNotBlank(originalFilename) && originalFilename.contains("%")) { + originalFilename = java.net.URLDecoder.decode(originalFilename, "UTF-8"); + } int index = originalFilename.lastIndexOf("."); //String[] filename = originalFilename.split("\\."); file = File.createTempFile(originalFilename.substring(0, index), originalFilename.substring(index + 1));