Browse Source

腾讯文件服务修改

yzc 1 year ago
parent
commit
89dc20a6e3

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

@@ -59,6 +59,9 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
     @Value("${obs.type:}")
     private String type;
 
+    @Value("${obs.region:}")
+    private String region;
+
     @Value("${obs.uploadMethod:}")
     private String uploadMethod;
 
@@ -163,7 +166,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

@@ -185,6 +185,7 @@ xss:
 
 obs:
   # type: huawei / tencent
+  # region: ap-shanghai
   # uploadMethod: 前端直传front 后端上传back
   # 腾讯云 ak对应secretId,sk对应secretKey
   ak: 9HNBVBHO7F3GLUCGTK5C