From c323e4ce593a886412bac2403a922ae2bf629655 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期一, 01 四月 2024 18:19:51 +0800
Subject: [PATCH] resource模块修复

---
 smart-man-boot/src/main/java/com/qianwen/smartman/modules/resource/endpoint/OssEndpointController.java |   82 ++++++++++++++++++++++-------------------
 1 files changed, 44 insertions(+), 38 deletions(-)

diff --git a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/resource/endpoint/OssEndpointController.java b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/resource/endpoint/OssEndpointController.java
index 9db0b37..aa45389 100644
--- a/smart-man-boot/src/main/java/com/qianwen/smartman/modules/resource/endpoint/OssEndpointController.java
+++ b/smart-man-boot/src/main/java/com/qianwen/smartman/modules/resource/endpoint/OssEndpointController.java
@@ -4,6 +4,8 @@
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.IoUtil;
 import io.swagger.annotations.Api;
+import me.zhyd.oauth.log.Log;
+
 import java.io.IOException;
 import java.io.InputStream;
 import javax.servlet.http.HttpServletResponse;
@@ -75,35 +77,21 @@
 
     @GetResource({"/file-content"})
     public void getFileContent(@RequestParam String fileName, HttpServletResponse response) {
-        InputStream objectStream;
-        Throwable th;
-        try {
-            objectStream = this.ossBuilder.template().getObject(fileName);
-            th = null;
-        } catch (IOException e) {
-            e.printStackTrace();
-        } catch (Exception e2) {
-            throw new ServiceException("鏂囦欢涓嶅瓨鍦�");
-        }
-        try {
+       
+        try (InputStream objectStream = this.ossBuilder.template().getObject(fileName)) {
             response.setContentType("application/octet-stream; charset=UTF-8");
             response.addHeader("Expires", "0");
             response.addHeader("Pragma", "no-cache");
             response.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
             IoUtil.copy(objectStream, response.getOutputStream());
-            if (objectStream != null) {
-                if (0 != 0) {
-                    try {
-                        objectStream.close();
-                    } catch (Throwable th2) {
-                        th.addSuppressed(th2);
-                    }
-                } else {
-                    objectStream.close();
-                }
-            }
-        } finally {
-        }
+            
+        } catch (IOException e) {
+        	Log.error("鑾峰彇鏂囦欢鍐呭閿欒",e);
+            e.printStackTrace();
+        } catch (Exception e) {
+            throw new ServiceException("鏂囦欢涓嶅瓨鍦�");
+        } 
+       
     }
 
     @PostResource({"/put-file"})
@@ -128,19 +116,31 @@
 
     @PostResource({"/put-file-attach"})
     public R<BladeFile> putFileAttach(@RequestParam MultipartFile file) {
-        String fileName = file.getOriginalFilename();
-        BladeFile bladeFile = this.ossBuilder.template().putFile(fileName, file.getInputStream());
-        Long attachId = buildAttach(fileName, Long.valueOf(file.getSize()), bladeFile);
-        bladeFile.setAttachId(attachId);
-        return R.data(bladeFile);
+    	try {
+	        String fileName = file.getOriginalFilename();
+	        BladeFile bladeFile = this.ossBuilder.template().putFile(fileName, file.getInputStream());
+	        Long attachId = buildAttach(fileName, Long.valueOf(file.getSize()), bladeFile);
+	        bladeFile.setAttachId(attachId);
+	        return R.data(bladeFile);
+    	} catch (Throwable ex) {
+   		 	//log.error("putFileAttachByName,寮傚父,file={}",fileName,ex);
+   		 	throw new ServiceException("putFileAttach寮傚父"+ex.getMessage());
+   	     
+   	  	} 
     }
 
     @PostResource({"/put-file-attach-by-name"})
     public R<BladeFile> putFileAttachByName(@RequestParam String fileName, @RequestParam MultipartFile file) {
-        BladeFile bladeFile = this.ossBuilder.template().putFile(fileName, file.getInputStream());
-        Long attachId = buildAttach(fileName, Long.valueOf(file.getSize()), bladeFile);
-        bladeFile.setAttachId(attachId);
-        return R.data(bladeFile);
+    	try {
+	        BladeFile bladeFile = this.ossBuilder.template().putFile(fileName, file.getInputStream());
+	        Long attachId = buildAttach(fileName, Long.valueOf(file.getSize()), bladeFile);
+	        bladeFile.setAttachId(attachId);
+	        return R.data(bladeFile);
+    	 } catch (Throwable ex) {
+    		 //log.error("putFileAttachByName,寮傚父,file={}",fileName,ex);
+    		 throw new ServiceException("putFileAttachByName寮傚父"+ex.getMessage());
+    	     
+    	  } 
     }
 
     private Long buildAttach(String fileName, Long fileSize, BladeFile bladeFile) {
@@ -170,10 +170,16 @@
 
     @PostResource({"/get-file-detail"})
     public R<BladeFile> getFileDetail(@RequestParam MultipartFile file) {
-        BladeFile bladeFile = this.ossBuilder.template().putFile(file.getName(), file.getInputStream());
-        long size = file.getSize();
-        Long attachId = buildAttach(file.getName(), Long.valueOf(size), bladeFile);
-        bladeFile.setAttachId(attachId);
-        return R.data(bladeFile);
+    	try {
+	        BladeFile bladeFile = this.ossBuilder.template().putFile(file.getName(), file.getInputStream());
+	        long size = file.getSize();
+	        Long attachId = buildAttach(file.getName(), Long.valueOf(size), bladeFile);
+	        bladeFile.setAttachId(attachId);
+	        return R.data(bladeFile);
+	    } catch (Throwable ex) {
+			 //log.error("putFileAttachByName,寮傚父,file={}",fileName,ex);
+			 throw new ServiceException("getFileDetail寮傚父"+ex.getMessage());
+		     
+		} 
     }
 }

--
Gitblit v1.9.3