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/AliyunCloudStorageServiceImpl.java | 25 +++++++++++++++---------- 1 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/AliyunCloudStorageServiceImpl.java b/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/AliyunCloudStorageServiceImpl.java index 7ac46e1..e6733c9 100644 --- a/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/AliyunCloudStorageServiceImpl.java +++ b/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/AliyunCloudStorageServiceImpl.java @@ -3,6 +3,7 @@ import com.aliyun.oss.ClientConfiguration; import com.aliyun.oss.OSSClient; import com.aliyun.oss.common.auth.DefaultCredentialProvider; +import com.ruoyi.oss.entity.UploadResult; import com.ruoyi.oss.enumd.CloudServiceEnumd; import com.ruoyi.oss.exception.OssException; import com.ruoyi.oss.factory.OssFactory; @@ -32,11 +33,15 @@ @Autowired public AliyunCloudStorageServiceImpl(CloudStorageProperties properties) { this.properties = properties.getAliyun(); - ClientConfiguration configuration = new ClientConfiguration(); - DefaultCredentialProvider credentialProvider = new DefaultCredentialProvider( - this.properties.getAccessKeyId(), - this.properties.getAccessKeySecret()); - client = new OSSClient(this.properties.getEndpoint(), credentialProvider, configuration); + try { + ClientConfiguration configuration = new ClientConfiguration(); + DefaultCredentialProvider credentialProvider = new DefaultCredentialProvider( + this.properties.getAccessKeyId(), + this.properties.getAccessKeySecret()); + client = new OSSClient(this.properties.getEndpoint(), credentialProvider, configuration); + } catch (Exception e) { + throw new IllegalArgumentException("闃块噷浜戝瓨鍌ㄩ厤缃敊璇�! 璇锋鏌ョ郴缁熼厤缃�!"); + } } @Override @@ -45,18 +50,18 @@ } @Override - public String upload(byte[] data, String path) { + public UploadResult upload(byte[] data, String path) { return upload(new ByteArrayInputStream(data), path); } @Override - public String upload(InputStream inputStream, String path) { + public UploadResult upload(InputStream inputStream, String path) { try { client.putObject(this.properties.getBucketName(), path, inputStream); } catch (Exception e) { throw new OssException("涓婁紶鏂囦欢澶辫触锛岃妫�鏌ラ厤缃俊鎭�"); } - return this.properties.getEndpoint() + "/" + path; + return new UploadResult().setUrl(properties.getEndpoint() + "/" + path).setFilename(path); } @Override @@ -70,12 +75,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