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 |   39 ++++++++++++++++++++++-----------------
 1 files changed, 22 insertions(+), 17 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 a8c9393..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,11 +6,12 @@
 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;
 import com.ruoyi.oss.properties.CloudStorageProperties;
-import com.ruoyi.oss.properties.QiniuProperties;
+import com.ruoyi.oss.properties.CloudStorageProperties.QiniuProperties;
 import com.ruoyi.oss.service.abstractd.AbstractCloudStorageService;
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -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