From a4c019ace2841faa6af14b5373a041464c3dbbde Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期二, 20 七月 2021 11:12:22 +0800 Subject: [PATCH] update OSS接口增加通用contentType --- ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageServiceImpl.java | 37 +++++++++++++++++++++---------------- 1 files changed, 21 insertions(+), 16 deletions(-) diff --git a/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageServiceImpl.java b/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageServiceImpl.java index 2f7a246..0b699ab 100644 --- a/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageServiceImpl.java +++ b/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageServiceImpl.java @@ -6,6 +6,7 @@ import com.qiniu.storage.Region; import com.qiniu.storage.UploadManager; import com.qiniu.util.Auth; +import com.ruoyi.oss.entity.UploadResult; import com.ruoyi.oss.enumd.CloudServiceEnumd; import com.ruoyi.oss.exception.OssException; import com.ruoyi.oss.factory.OssFactory; @@ -36,16 +37,20 @@ @Autowired public QiniuCloudStorageServiceImpl(CloudStorageProperties properties) { this.properties = properties.getQiniu(); - // z0 z1 z2 - Configuration config = new Configuration(Region.autoRegion()); - // 榛樿涓嶄娇鐢╤ttps - config.useHttpsDomains = false; - uploadManager = new UploadManager(config); - Auth auth = Auth.create( - this.properties.getAccessKey(), - this.properties.getSecretKey()); - token = auth.uploadToken(this.properties.getBucketName()); - bucketManager = new BucketManager(auth, config); + try { + // z0 z1 z2 + Configuration config = new Configuration(Region.autoRegion()); + // 榛樿涓嶄娇鐢╤ttps + config.useHttpsDomains = false; + uploadManager = new UploadManager(config); + Auth auth = Auth.create( + this.properties.getAccessKey(), + this.properties.getSecretKey()); + token = auth.uploadToken(this.properties.getBucketName()); + bucketManager = new BucketManager(auth, config); + } catch (Exception e) { + throw new IllegalArgumentException("涓冪墰浜戝瓨鍌ㄩ厤缃敊璇�! 璇锋鏌ョ郴缁熼厤缃�!"); + } } @@ -55,7 +60,7 @@ } @Override - public String upload(byte[] data, String path) { + public UploadResult upload(byte[] data, String path, String contentType) { try { Response res = uploadManager.put(data, path, token); if (!res.isOK()) { @@ -64,7 +69,7 @@ } catch (Exception e) { throw new OssException("涓婁紶鏂囦欢澶辫触锛岃鏍稿涓冪墰閰嶇疆淇℃伅"); } - return this.properties.getDomain() + "/" + path; + return new UploadResult().setUrl(properties.getDomain() + "/" + path).setFilename(path); } @Override @@ -81,13 +86,13 @@ } @Override - public String uploadSuffix(byte[] data, String suffix) { - return upload(data, getPath(this.properties.getPrefix(), suffix)); + public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) { + return upload(data, getPath(this.properties.getPrefix(), suffix), contentType); } @Override - public String uploadSuffix(InputStream inputStream, String suffix) { - return upload(inputStream, getPath(this.properties.getPrefix(), suffix)); + public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) { + return upload(inputStream, getPath(this.properties.getPrefix(), suffix), contentType); } @Override -- Gitblit v1.9.3