Explorar el Código

修改上传下载方法

zyl hace 3 meses
padre
commit
3b95273c26

+ 2 - 2
liutongyi-admin/src/main/resources/application.yml

@@ -9,9 +9,9 @@ citygis:
   # 默认,文件路径 示例( Windows配置D:/citygis/uploadPath,Linux配置 /home/citygis/uploadPath)
   profile: D:/citygis/uploadPath
   #  window上传路径
-  windows_profile: D:/citygis/uploadPath
+  windows_profile: D:/citygis_liutongyi/file
   #  Linux上传路径
-  linux_profile: /opt/citygis/uploadFile
+  linux_profile: /opt/citygis_liutongyi/file
   # 获取ip地址开关
   addressEnabled: false
   # 验证码类型 math 数字计算 char 字符验证

+ 14 - 5
liutongyi-common/src/main/java/com/citygis/common/utils/file/FileUploadUtils.java

@@ -98,9 +98,7 @@ public class FileUploadUtils
      * @throws InvalidExtensionException 文件校验异常
      */
     public static final String upload(String baseDir, MultipartFile file, String[] allowedExtension)
-            throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
-            InvalidExtensionException
-    {
+            throws Exception {
         int fileNamelength = Objects.requireNonNull(file.getOriginalFilename()).length();
         if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
         {
@@ -139,13 +137,24 @@ public class FileUploadUtils
         return desc;
     }
 
-    public static final String getPathFileName(String uploadDir, String fileName) throws IOException
+    public static final String getPathFileName(String uploadDir, String fileName) throws Exception
     {
-        int dirLastIndex = com.citygis.common.config.CitygisConfig.getProfile().length() + 1;
+        int dirLastIndex = getSystemType().length() + 1;
         String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
         return  "/" + currentDir + "/" + fileName;
     }
 
+    public static String getSystemType() throws Exception {
+        String osName = System.getProperty("os.name").toLowerCase();
+        if (osName.contains("win")) {
+            return com.citygis.common.config.CitygisConfig.getWindows_profile();
+        } else if (osName.contains("nix") || osName.contains("nux") || osName.contains("mac")) {
+            return com.citygis.common.config.CitygisConfig.getLinux_profile();
+        } else {
+            return "unknown";
+        }
+    }
+
     /**
      * 文件大小校验
      *

+ 1 - 1
liutongyi-common/src/main/java/com/citygis/common/utils/file/FileUtils.java

@@ -78,7 +78,7 @@ public class FileUtils
      * @return 目标文件
      * @throws IOException IO异常
      */
-    public static String writeBytes(byte[] data, String uploadDir) throws IOException
+    public static String writeBytes(byte[] data, String uploadDir) throws Exception
     {
         FileOutputStream fos = null;
         String pathName = "";