Przeglądaj źródła

!302 【轻量级 PR】 文件上传服务获取InputStream未关闭
Merge pull request !302 from 程序凡/master

若依 3 lat temu
rodzic
commit
26c63520f2

+ 7 - 3
ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/FastDfsSysFileServiceImpl.java

@@ -8,9 +8,11 @@ import com.github.tobato.fastdfs.domain.fdfs.StorePath;
8 8
 import com.github.tobato.fastdfs.service.FastFileStorageClient;
9 9
 import com.ruoyi.common.core.utils.file.FileTypeUtils;
10 10
 
11
+import java.io.InputStream;
12
+
11 13
 /**
12 14
  * FastDFS 文件存储
13
- * 
15
+ *
14 16
  * @author ruoyi
15 17
  */
16 18
 @Service
@@ -27,7 +29,7 @@ public class FastDfsSysFileServiceImpl implements ISysFileService
27 29
 
28 30
     /**
29 31
      * FastDfs文件上传接口
30
-     * 
32
+     *
31 33
      * @param file 上传的文件
32 34
      * @return 访问地址
33 35
      * @throws Exception
@@ -35,8 +37,10 @@ public class FastDfsSysFileServiceImpl implements ISysFileService
35 37
     @Override
36 38
     public String uploadFile(MultipartFile file) throws Exception
37 39
     {
38
-        StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(),
40
+        InputStream inputStream = file.getInputStream();
41
+        StorePath storePath = storageClient.uploadFile(inputStream, file.getSize(),
39 42
                 FileTypeUtils.getExtension(file), null);
43
+        inputStream.close();
40 44
         return domain + "/" + storePath.getFullPath();
41 45
     }
42 46
 }

+ 8 - 4
ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/service/MinioSysFileServiceImpl.java

@@ -8,9 +8,11 @@ import com.ruoyi.file.utils.FileUploadUtils;
8 8
 import io.minio.MinioClient;
9 9
 import io.minio.PutObjectArgs;
10 10
 
11
+import java.io.InputStream;
12
+
11 13
 /**
12 14
  * Minio 文件存储
13
- * 
15
+ *
14 16
  * @author ruoyi
15 17
  */
16 18
 @Service
@@ -23,8 +25,8 @@ public class MinioSysFileServiceImpl implements ISysFileService
23 25
     private MinioClient client;
24 26
 
25 27
     /**
26
-     * 本地文件上传接口
27
-     * 
28
+     * Minio文件上传接口
29
+     *
28 30
      * @param file 上传的文件
29 31
      * @return 访问地址
30 32
      * @throws Exception
@@ -33,13 +35,15 @@ public class MinioSysFileServiceImpl implements ISysFileService
33 35
     public String uploadFile(MultipartFile file) throws Exception
34 36
     {
35 37
         String fileName = FileUploadUtils.extractFilename(file);
38
+        InputStream inputStream = file.getInputStream();
36 39
         PutObjectArgs args = PutObjectArgs.builder()
37 40
                 .bucket(minioConfig.getBucketName())
38 41
                 .object(fileName)
39
-                .stream(file.getInputStream(), file.getSize(), -1)
42
+                .stream(inputStream, file.getSize(), -1)
40 43
                 .contentType(file.getContentType())
41 44
                 .build();
42 45
         client.putObject(args);
46
+        inputStream.close();
43 47
         return minioConfig.getUrl() + "/" + minioConfig.getBucketName() + "/" + fileName;
44 48
     }
45 49
 }