|
@@ -7,6 +7,7 @@ import org.springframework.web.multipart.MultipartFile;
|
7
|
7
|
|
8
|
8
|
import java.io.ByteArrayInputStream;
|
9
|
9
|
import java.io.IOException;
|
|
10
|
+import java.io.InputStream;
|
10
|
11
|
import java.util.Date;
|
11
|
12
|
|
12
|
13
|
/**
|
|
@@ -43,4 +44,27 @@ public class ImageServiceimpl implements ImageServiceI {
|
43
|
44
|
url = url.substring(0, url.lastIndexOf("&Signature"));
|
44
|
45
|
return url;
|
45
|
46
|
}
|
|
47
|
+
|
|
48
|
+ @Override
|
|
49
|
+ public String getImageUrl(InputStream uploadFile) throws IOException {
|
|
50
|
+
|
|
51
|
+ String imgName = System.currentTimeMillis() + ".png";
|
|
52
|
+ // 创建OSSClient实例
|
|
53
|
+ OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
|
54
|
+ // 上传
|
|
55
|
+ long time = System.currentTimeMillis();
|
|
56
|
+
|
|
57
|
+ ossClient.putObject(bucketName, imgName, uploadFile);
|
|
58
|
+
|
|
59
|
+ // 关闭client
|
|
60
|
+ ossClient.shutdown();
|
|
61
|
+ Date expiration = new Date(time + 3600 * 1000 * 24 * 365 * 10);
|
|
62
|
+ String url = ossClient.generatePresignedUrl(bucketName, imgName, expiration).toString();
|
|
63
|
+
|
|
64
|
+ // 截取掉签名
|
|
65
|
+ url = url.substring(0, url.lastIndexOf("&Signature"));
|
|
66
|
+ return url;
|
|
67
|
+
|
|
68
|
+ return null;
|
|
69
|
+ }
|
46
|
70
|
}
|