فهرست منبع

委外文件encode

lipenghui 3 هفته پیش
والد
کامیت
faab47507f

+ 14 - 0
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/io/FileUtils.java

@@ -15,9 +15,11 @@ import lombok.SneakyThrows;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLEncoder;
 import java.util.Date;
 
 /**
@@ -135,4 +137,16 @@ public class FileUtils {
         }
         return fullPath.substring(lastSlashIndex + 1);
     }
+
+    public static String encodePathSegment(String pathSegment) {
+        try {
+            // 使用UTF-8编码,符合现代Web标准
+            String encoded = URLEncoder.encode(pathSegment, "UTF-8");
+            // 替换空格编码:URLEncoder会将空格转为+,而URL路径中推荐使用%20
+            return encoded.replace("+", "%20");
+        } catch (UnsupportedEncodingException e) {
+            // UTF-8是Java标准编码,不会抛出此异常
+            throw new RuntimeException("URL编码失败", e);
+        }
+    }
 }

+ 3 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/oa/OaFlow.java

@@ -262,7 +262,9 @@ public class OaFlow {
         List<ImmutableMap> files = new ArrayList<>();
         strings.forEach(e ->{
             String fileName = FileUtils.getFileNameByUrlParse(e);
-            files.add(ImmutableMap.of("filePath", e,"fileName", fileName));
+            String s1 = FileUtils.encodePathSegment(fileName);
+            String s = StringUtils.substringBeforeLast(e, "/");
+            files.add(ImmutableMap.of("filePath", s+"/"+s1,"fileName", fileName));
         });
 
         OutRepairFlow flow16 = new OutRepairFlow().setFieldName("fjsc").setFieldValue(JSON.toJSONString(files));