From 0a128e454cf644d094eccf4b8790f217f28e94f7 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期一, 19 七月 2021 19:40:18 +0800 Subject: [PATCH] update 编写 Minio 实现 调整OSS模块结构 --- ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QcloudCloudStorageServiceImpl.java | 29 +++++++++++++++++------------ 1 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QcloudCloudStorageServiceImpl.java b/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QcloudCloudStorageServiceImpl.java index 2b1b023..883f10e 100644 --- a/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QcloudCloudStorageServiceImpl.java +++ b/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QcloudCloudStorageServiceImpl.java @@ -5,6 +5,7 @@ import com.qcloud.cos.auth.BasicCOSCredentials; import com.qcloud.cos.auth.COSCredentials; import com.qcloud.cos.region.Region; +import com.ruoyi.oss.entity.UploadResult; import com.ruoyi.oss.enumd.CloudServiceEnumd; import com.ruoyi.oss.factory.OssFactory; import com.ruoyi.oss.properties.CloudStorageProperties; @@ -32,14 +33,18 @@ @Autowired public QcloudCloudStorageServiceImpl(CloudStorageProperties properties) { this.properties = properties.getQcloud(); - COSCredentials credentials = new BasicCOSCredentials( - this.properties.getSecretId(), - this.properties.getSecretKey()); - // 鍒濆鍖栧鎴风閰嶇疆 - ClientConfig clientConfig = new ClientConfig(); - // 璁剧疆bucket鎵�鍦ㄧ殑鍖哄煙锛屽崕鍗楋細gz 鍗庡寳锛歵j 鍗庝笢锛歴h - clientConfig.setRegion(new Region(this.properties.getRegion())); - client = new COSClient(credentials, clientConfig); + try { + COSCredentials credentials = new BasicCOSCredentials( + this.properties.getSecretId(), + this.properties.getSecretKey()); + // 鍒濆鍖栧鎴风閰嶇疆 + ClientConfig clientConfig = new ClientConfig(); + // 璁剧疆bucket鎵�鍦ㄧ殑鍖哄煙锛屽崕鍗楋細gz 鍗庡寳锛歵j 鍗庝笢锛歴h + clientConfig.setRegion(new Region(this.properties.getRegion())); + client = new COSClient(credentials, clientConfig); + } catch (Exception e) { + throw new IllegalArgumentException("鑵捐浜戝瓨鍌ㄩ厤缃敊璇�! 璇锋鏌ョ郴缁熼厤缃�!"); + } } @Override @@ -48,7 +53,7 @@ } @Override - public String upload(byte[] data, String path) { + public UploadResult upload(byte[] data, String path) { // 鑵捐浜戝繀闇�瑕佷互"/"寮�澶� if (!path.startsWith("/")) { path = "/" + path; @@ -60,7 +65,7 @@ // if (Convert.toInt(jsonObject.get("code")) != 0) { // throw new OssException("鏂囦欢涓婁紶澶辫触锛�" + Convert.toStr(jsonObject.get("message"))); // } - return this.properties.getDomain() + path; + return new UploadResult().setUrl(properties.getDomain() + "/" + path).setFilename(path); } @Override @@ -75,12 +80,12 @@ } @Override - public String uploadSuffix(byte[] data, String suffix) { + public UploadResult uploadSuffix(byte[] data, String suffix) { return upload(data, getPath(this.properties.getPrefix(), suffix)); } @Override - public String uploadSuffix(InputStream inputStream, String suffix) { + public UploadResult uploadSuffix(InputStream inputStream, String suffix) { return upload(inputStream, getPath(this.properties.getPrefix(), suffix)); } -- Gitblit v1.9.3