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/QcloudCloudStorageServiceImpl.java |   33 +++++++++++++++++++--------------
 1 files changed, 19 insertions(+), 14 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..3376b8d 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, String contentType) {
 		// 鑵捐浜戝繀闇�瑕佷互"/"寮�澶�
 		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,13 +80,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