Browse Source

文件关流

cuimengchao 3 years ago
parent
commit
7721ff39cf
1 changed files with 11 additions and 1 deletions
  1. 11 1
      fyzd-phone/src/main/java/com/yx/face/boot/uitls/MiniOUtils.java

+ 11 - 1
fyzd-phone/src/main/java/com/yx/face/boot/uitls/MiniOUtils.java

@@ -7,6 +7,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Component;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.text.SimpleDateFormat;
 
@@ -22,7 +23,7 @@ import java.text.SimpleDateFormat;
 @Component
 public class MiniOUtils {
 
-//    @Value("${web.address}")
+    //    @Value("${web.address}")
     private static final String ip = "https://ldb-airport.hz-hanghui.com:9100/img/";
 
 //    /**
@@ -123,8 +124,17 @@ public class MiniOUtils {
                     .object(fileName)
                     .stream(inputStream, Long.valueOf(inputStream.available()), -1l)
                     .contentType(contentType).build());
+            inputStream.close();
         } catch (Exception e) {
             new RuntimeException("上传发生错误!");
+        } finally {
+            if (inputStream != null) {
+                try {
+                    inputStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
         }
         return ip + bucketName + "/" + fileName;
     }