|
@@ -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
|
+}
|