Browse Source

提交分支

魏超 6 years ago
parent
commit
1d1c804321

+ 9
- 16
CODE/smart-community/app-api/src/main/java/com/community/huiju/controller/ImageController.java View File

1
 package com.community.huiju.controller;
1
 package com.community.huiju.controller;
2
 
2
 
3
 import com.aliyun.oss.OSSClient;
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
 import org.springframework.cloud.context.config.annotation.RefreshScope;
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
 import org.springframework.web.multipart.MultipartFile;
7
 import org.springframework.web.multipart.MultipartFile;
14
 
8
 
15
 import java.io.ByteArrayInputStream;
9
 import java.io.ByteArrayInputStream;
27
 @Api(value = "图片操作API", description = "图片操作API")
21
 @Api(value = "图片操作API", description = "图片操作API")
28
 public class ImageController {
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
     @ApiOperation(value = "图片上传以及获取url", notes = "图片上传以及获取url")
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
         // 创建OSSClient实例
34
         // 创建OSSClient实例
42
         OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
35
         OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
43
         // 上传
36
         // 上传