Browse Source

20230426_sunOBS文件上传

15143018065 1 year ago
parent
commit
a05804ba12

+ 8 - 12
ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/controller/SysFileController.java

@@ -18,16 +18,12 @@ import org.apache.commons.lang3.ObjectUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.PostConstruct;
 import javax.servlet.http.HttpServletResponse;
 import java.io.*;
-import java.net.URLDecoder;
 import java.nio.charset.StandardCharsets;
 
 /**
@@ -90,7 +86,7 @@ public class SysFileController
                 // 上传并返回访问地址
                 obsClient = new ObsClient(obsConfig.getAK(), obsConfig.getSK(), obsConfig.getENDPOINT());
                 PutObjectResult putObjectResult = obsClient.putObject(obsConfig.getBUCKET_NAME(),
-                        "mz/" + objectKey, file.getInputStream());
+                        "mzylfwobs/" + objectKey, file.getInputStream());
                 sysFile.setName(putObjectResult.getObjectKey());
                 sysFile.setUrl(putObjectResult.getObjectUrl());
                 return R.ok(sysFile);
@@ -186,12 +182,12 @@ public class SysFileController
         }
     }
 
-    @GetMapping("/commonPreview")
-    public void commonPreview(String objectKey, HttpServletResponse resp) {
+    @GetMapping("/mzylfwobs/{year}/{month}/{day}/{fileName}")
+    public void commonPreview(@PathVariable("year") String year, @PathVariable("month") String month,
+        @PathVariable("day") String day, @PathVariable("fileName") String fileName, HttpServletResponse resp) {
         try {
-            objectKey = URLDecoder.decode(objectKey, "utf-8");
-            String[] arr = objectKey.split("/");
-            String fileName = arr[arr.length - 1];
+//            objectKey = URLDecoder.decode(objectKey, "utf-8");
+            String objectKey = "mzylfwobs/" + year + "/" + month + "/" + day + "/" + fileName;
             int index = fileName.lastIndexOf(".");
             char[] ch = fileName.toCharArray();
             String lastString = String.copyValueOf(ch, index + 1, ch.length - index - 1);
@@ -205,7 +201,7 @@ public class SysFileController
             convertOutputStream2(resp, obsConfig.getBUCKET_NAME(), objectKey);
         } catch (Exception e) {
             log.error("取得文件失败==》", e);
-            e.printStackTrace();
+//            e.printStackTrace();
         }
     }
 

+ 3 - 0
ruoyi-ui/docker/prod/nginx.conf

@@ -39,6 +39,9 @@ http {
         location /uploadPath/ {
            proxy_pass http://19.135.92.130:8080/file/uploadPath/;
         }
+        location /mzylfwobs/ {
+           proxy_pass http://19.135.92.130:8080/file/mzylfwobs/;
+        }
         location / {
             root /usr/share/nginx/html;
             index index.html index.html;

+ 3 - 0
ruoyi-ui/nginx.conf

@@ -39,6 +39,9 @@ http {
         location /uploadPath/ {
            proxy_pass http://172.17.0.1:9090/file/uploadPath/;
         }
+        location /mzylfwobs/ {
+           proxy_pass http://172.17.0.1:9090/file/mzylfwobs/;
+        }
         location / {
             root /usr/share/nginx/html;
             index index.html index.html;

+ 8 - 1
ruoyi-ui/vue.config.js

@@ -53,11 +53,18 @@ module.exports = {
         }
       },
       '/uploadPath': {
-        target: `http://121.36.73.159:803/uploadPath`,
+        target: `http://localhost:8080/file/uploadPath`,
         changeOrigin: true,
         pathRewrite: {
           ['^' + '/uploadPath']: ''
         }
+      },
+      '/mzylfwobs': {
+        target: `http://localhost:8080/file/mzylfwobs`,
+        changeOrigin: true,
+        pathRewrite: {
+          ['^' + '/mzylfwobs']: ''
+        }
       }
     },
     disableHostCheck: true

+ 3 - 0
ruoyi-web/docker/prod/nginx.conf

@@ -39,6 +39,9 @@ http {
         location /uploadPath/ {
            proxy_pass http://19.135.92.130:8080/file/uploadPath/;
         }
+        location /mzylfwobs/ {
+           proxy_pass http://19.135.92.130:8080/file/mzylfwobs/;
+        }
         location / {
             root /usr/share/nginx/html;
             index index.html index.html;

+ 3 - 0
ruoyi-web/nginx.conf

@@ -39,6 +39,9 @@ http {
         location /uploadPath/ {
            proxy_pass http://172.17.0.1:9090/file/uploadPath/;
         }
+        location /mzylfwobs/ {
+           proxy_pass http://172.17.0.1:9090/file/mzylfwobs/;
+        }
         location / {
             root /usr/share/nginx/html;
             index index.html index.html;

+ 5 - 0
ruoyi-web/vite.config.js

@@ -44,6 +44,11 @@ export default defineConfig(({ mode, command }) => {
           target: `http://121.36.73.159:801/uploadPath`,
           changeOrigin: true,
           rewrite: (p) => p.replace(/^\/uploadPath/, '')
+        },
+        '/mzylfwobs': {
+          target: `http://localhost:8080/mzylfwobs`,
+          changeOrigin: true,
+          rewrite: (p) => p.replace(/^\/mzylfwobs/, '')
         }
       }
     },