瀏覽代碼

提交分支

魏超 6 年之前
父節點
當前提交
1d1c804321

+ 9
- 16
CODE/smart-community/app-api/src/main/java/com/community/huiju/controller/ImageController.java 查看文件

@@ -1,15 +1,9 @@
1 1
 package com.community.huiju.controller;
2 2
 
3 3
 import com.aliyun.oss.OSSClient;
4
-import io.swagger.annotations.Api;
5
-import io.swagger.annotations.ApiImplicitParam;
6
-import io.swagger.annotations.ApiImplicitParams;
7
-import io.swagger.annotations.ApiOperation;
4
+import io.swagger.annotations.*;
8 5
 import org.springframework.cloud.context.config.annotation.RefreshScope;
9
-import org.springframework.web.bind.annotation.RequestMapping;
10
-import org.springframework.web.bind.annotation.RequestMethod;
11
-import org.springframework.web.bind.annotation.RequestParam;
12
-import org.springframework.web.bind.annotation.RestController;
6
+import org.springframework.web.bind.annotation.*;
13 7
 import org.springframework.web.multipart.MultipartFile;
14 8
 
15 9
 import java.io.ByteArrayInputStream;
@@ -27,17 +21,16 @@ import java.util.Date;
27 21
 @Api(value = "图片操作API", description = "图片操作API")
28 22
 public class ImageController {
29 23
 
30
-    private static String imgName = System.currentTimeMillis() + ".png";
31
-    private static String endpoint = "http://oss-cn-beijing.aliyuncs.com";
32
-    private static String accessKeyId = "LTAIkc75dpkJw8Lb";
33
-    private static String accessKeySecret = "v4bvXCaix6vSDTCFfwSAdqV53iFEQw";
34
-    private static String bucketName = "yc-smart-community";
24
+    private static String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
25
+    private static String accessKeyId = "LTAIiG6xeHbVzTXC";
26
+    private static String accessKeySecret = "YUci8oBtm5WzobH6SP2eyZUbjCBKBo";
27
+    private static String bucketName = "imgurlspace";
35 28
 
36 29
     @ApiOperation(value = "图片上传以及获取url", notes = "图片上传以及获取url")
37
-    @ApiImplicitParams({@ApiImplicitParam(paramType = "form",dataType = "file",name = "uploadFile",value = "图片")})
38
-    @RequestMapping(value = "/getUrl", method = RequestMethod.POST)
39
-    public static String uploadImgAndGetUrl(@RequestParam("file") MultipartFile uploadFile) throws Exception {
30
+    @PostMapping(value = "/getUrl", consumes = "multipart/*", headers = "content-type=multipart/form-data")
31
+    public String uploadImgAndGetUrl(@ApiParam(value = "file" ,required = true) MultipartFile uploadFile) throws Exception {
40 32
 
33
+        String imgName = System.currentTimeMillis() + ".png";
41 34
         // 创建OSSClient实例
42 35
         OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
43 36
         // 上传