From adaa3e1db81d1e3c094d5f6d8a1181b82216d71c Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Wed, 25 Dec 2024 16:30:44 +0800
Subject: [PATCH] 代码生成新增配置是否允许文件覆盖到本地

---
 ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/FastDfsSysFileServiceImpl.java |   31 ++++++++++++++++++++++---------
 1 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/FastDfsSysFileServiceImpl.java b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/FastDfsSysFileServiceImpl.java
index 202fdab..da0dc60 100644
--- a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/FastDfsSysFileServiceImpl.java
+++ b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/FastDfsSysFileServiceImpl.java
@@ -1,16 +1,18 @@
 package com.ruoyi.file.service;
 
-import org.apache.commons.io.FilenameUtils;
+import java.io.InputStream;
+import com.alibaba.nacos.common.utils.IoUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 import com.github.tobato.fastdfs.domain.fdfs.StorePath;
 import com.github.tobato.fastdfs.service.FastFileStorageClient;
+import com.ruoyi.common.core.utils.file.FileTypeUtils;
 
 /**
- * FastDFS文件存储
- * 
+ * FastDFS 文件存储
+ *
  * @author ruoyi
  */
 @Service
@@ -27,17 +29,28 @@
 
     /**
      * FastDfs文件上传接口
-     * 
+     *
      * @param file 上传的文件
-     * @param baseDir 相对应用的基目录
      * @return 访问地址
      * @throws Exception
      */
     @Override
-    public String uploadFile(MultipartFile file, String baseDir) throws Exception
+    public String uploadFile(MultipartFile file) throws Exception
     {
-        StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(),
-                FilenameUtils.getExtension(file.getOriginalFilename()), null);
-        return domain + "/" + storePath.getFullPath();
+        InputStream inputStream = null;
+        try
+        {
+            inputStream = file.getInputStream();
+            StorePath storePath = storageClient.uploadFile(inputStream, file.getSize(), FileTypeUtils.getExtension(file), null);
+            return domain + "/" + storePath.getFullPath();
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException("FastDfs Failed to upload file", e);
+        }
+        finally
+        {
+            IoUtils.closeQuietly(inputStream);
+        }
     }
 }

--
Gitblit v1.9.3