张延森 4 years ago
parent
commit
508e787886
1 changed files with 34 additions and 0 deletions
  1. 34
    0
      src/main/java/com/shigongli/controller/CommController.java

+ 34
- 0
src/main/java/com/shigongli/controller/CommController.java View File

@@ -0,0 +1,34 @@
1
+package com.shigongli.controller;
2
+
3
+import com.shigongli.common.BaseController;
4
+import com.shigongli.common.OSSUtils;
5
+import com.shigongli.common.ResponseBean;
6
+import io.swagger.annotations.ApiOperation;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.web.bind.annotation.PostMapping;
9
+import org.springframework.web.bind.annotation.RequestParam;
10
+import org.springframework.web.multipart.MultipartFile;
11
+
12
+import java.io.IOException;
13
+
14
+public class CommController extends BaseController {
15
+
16
+    @Autowired
17
+    OSSUtils ossUtils;
18
+
19
+    /**
20
+     * 图片
21
+     * @param multipartFile
22
+     * @return
23
+     */
24
+    @ApiOperation(value = "图片上传", notes = "图片上传")
25
+    @PostMapping("/{plat}/image")
26
+    public ResponseBean uploadImage(@RequestParam("file") MultipartFile multipartFile) {
27
+        try {
28
+            String img = ossUtils.putObject(multipartFile, "/shigongli/images/");
29
+            return ResponseBean.success(img);
30
+        } catch (IOException e) {
31
+            return ResponseBean.error("上传图片失败: " + e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);
32
+        }
33
+    }
34
+}