Explorar el Código

腾讯文件服务修改

yzc hace 1 año
padre
commit
7faec288e8

+ 4 - 1
hx-file/src/main/java/com/fjhx/file/service/impl/FileInfoServiceImpl.java

@@ -57,6 +57,9 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
     @Value("${obs.type:}")
     private String type;
 
+    @Value("${obs.region:}")
+    private String region;
+
     @Value("${obs.bucketName}")
     private String bucketName;
 
@@ -135,7 +138,7 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
 
         //腾讯云COS对象存储
         if (Objects.equals(type, "tencent")) {
-            TencentCosUtils.uploadFile(ak, sk, bucketName, objectKey, file);
+            TencentCosUtils.uploadFile(ak, sk, bucketName, region, objectKey, file);
         }
         //华为云OBS对象存储(默认)
         else if (Objects.equals(type, "huawei")) {

+ 2 - 2
hx-file/src/main/java/com/fjhx/file/utils/TencentCosUtils.java

@@ -17,9 +17,9 @@ import org.springframework.web.multipart.MultipartFile;
 @Slf4j
 public class TencentCosUtils {
 
-    public static void uploadFile(String secretId, String secretKey, String bucketName, String objectKey, MultipartFile file) {
+    public static void uploadFile(String secretId, String secretKey, String bucketName, String regionStr, String objectKey, MultipartFile file) {
         COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
-        Region region = new Region("ap-shanghai");
+        Region region = new Region(regionStr);
         ClientConfig clientConfig = new ClientConfig(region);
         clientConfig.setHttpProtocol(HttpProtocol.https);
         COSClient cosClient = new COSClient(cred, clientConfig);

+ 1 - 0
ruoyi-admin/src/main/resources/application.yml

@@ -192,6 +192,7 @@ obs:
 #obs:
 #  #huawei / tencent
 #  type: tencent
+#  region: ap-shanghai
 #  #secretId
 #  ak: AKIDmPqHhzAHM9sSwFd4dHpIm9MNBnMnIk7T
 #  #secretKey