Selaa lähdekoodia

Merge branch 'master' of http://git.ycjcjy.com/fuxingfan/foyo

周立森 5 vuotta sitten
vanhempi
commit
e102edae66

+ 0
- 5
foyo-service/pom.xml Näytä tiedosto

@@ -51,11 +51,6 @@
51 51
 			<version>1.2.56</version>
52 52
 			<scope>compile</scope>
53 53
 		</dependency>
54
-		<dependency>
55
-			<groupId>com.aliyun.oss</groupId>
56
-			<artifactId>aliyun-sdk-oss</artifactId>
57
-			<version>2.8.3</version>
58
-		</dependency>
59 54
 
60 55
 		<dependency>
61 56
 			<groupId>com.github.pagehelper</groupId>

+ 17
- 23
foyo-service/src/main/java/com/huiju/foyo/service/impl/ImageServiceimpl.java Näytä tiedosto

@@ -1,11 +1,12 @@
1 1
 package com.huiju.foyo.service.impl;
2 2
 
3
-import com.aliyun.oss.OSSClient;
4 3
 import com.huiju.foyo.service.ImageServiceI;
4
+import org.springframework.beans.factory.annotation.Value;
5 5
 import org.springframework.stereotype.Service;
6 6
 import org.springframework.web.multipart.MultipartFile;
7 7
 
8 8
 import java.io.ByteArrayInputStream;
9
+import java.io.File;
9 10
 import java.io.IOException;
10 11
 import java.util.Date;
11 12
 
@@ -17,30 +18,23 @@ import java.util.Date;
17 18
  */
18 19
 @Service("ImageService")
19 20
 public class ImageServiceimpl implements ImageServiceI {
20
-
21
-    private static String endpoint = "http://oss-cn-shanghai.aliyuncs.com";
22
-    private static String accessKeyId = "LTAIkc75dpkJw8Lb";
23
-    private static String accessKeySecret = "v4bvXCaix6vSDTCFfwSAdqV53iFEQw";
24
-    private static String bucketName = "jingcheng-h5temp";
25
-
21
+    
26 22
     @Override
27 23
     public String getImageUrl(MultipartFile uploadFile) throws IOException {
28
-
24
+        //保存的文件名
29 25
         String imgName = System.currentTimeMillis() + ".png";
30
-        // 创建OSSClient实例
31
-        OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
32
-        // 上传
33
-        long time = System.currentTimeMillis();
34
-
35
-        ossClient.putObject(bucketName, imgName, new ByteArrayInputStream(uploadFile.getBytes()));
36
-
37
-        // 关闭client
38
-        ossClient.shutdown();
39
-        Date expiration = new Date(time + 3600 * 1000 * 24 * 365 * 10);
40
-        String url = ossClient.generatePresignedUrl(bucketName, imgName, expiration).toString();
41
-
42
-        // 截取掉签名
43
-        url = url.substring(0, url.lastIndexOf("&Signature"));
44
-        return url;
26
+        //保存路径
27
+        String path = "D:\\test\\images\\" + imgName;
28
+        String rebackPath = "images\\" + imgName;
29
+        //生成保存文件
30
+        File troUploadFile = new File(path);
31
+        //将上传文件保存到路径
32
+        try {
33
+            uploadFile.transferTo(troUploadFile);
34
+        } catch (IOException e) {
35
+            e.printStackTrace();
36
+        }
37
+        
38
+        return rebackPath;
45 39
     }
46 40
 }