Browse Source

no message

FengChaoYu 2 days ago
parent
commit
01c045e72e
1 changed files with 40 additions and 0 deletions
  1. 40 0
      src/main/java/com/gree/mall/contest/controller/OSSController.java

+ 40 - 0
src/main/java/com/gree/mall/contest/controller/OSSController.java

@@ -0,0 +1,40 @@
+package com.gree.mall.contest.controller;
+
+import com.gree.mall.contest.annotation.ApiNotAuth;
+import com.gree.mall.contest.exception.RemoteServiceException;
+import com.gree.mall.contest.logic.common.CommonLogic;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+
+@Slf4j
+@RestController
+@Tag(name = "获取OSS文件", description = "获取OSS文件")
+@RequestMapping(produces = "application/json; charset=utf-8")
+@RequiredArgsConstructor
+public class OSSController {
+
+    private final CommonLogic commonLogic;
+
+    @ApiNotAuth
+    @GetMapping("/img/get")
+    @Operation(summary = "获取图片")
+    public void getImg(
+            @Parameter(required = true, description = "附件key") @RequestParam(required = true) String key,
+            HttpServletResponse response
+    ) throws IOException, RemoteServiceException {
+        String file = commonLogic.getFile(key);
+        response.sendRedirect(file);
+    }
+
+}