Przeglądaj źródła

阿里云oss修改为内网上传

wang-hai-cheng 5 lat temu
rodzic
commit
c277881dd8

+ 7 - 3
lift-business-service/src/main/java/cn/com/ty/lift/business/common/CommonController.java

@@ -44,9 +44,9 @@ public class CommonController {
     private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd");
 
     private RedisTemplate<String, Object> redisTemplate;
-    private SystemConfiguration           systemConfiguration;
-    private AnnualInspectionService       annualInspectionService;
-    private EmergencyRepairService        emergencyRepairService;
+    private SystemConfiguration systemConfiguration;
+    private AnnualInspectionService annualInspectionService;
+    private EmergencyRepairService emergencyRepairService;
     private CapitalRepairLiftRelevanceService capitalRepairLiftRelevanceService;
     private MaintenancePlanService maintenancePlanService;
     private AreaCodeMapper codeMapper;
@@ -108,6 +108,8 @@ public class CommonController {
                 String url = systemConfiguration.build().putObject(entry.getKey(), entry.getValue().getBytes());
                 log.info("upload file complete, file URL: {}", url);
                 Validate.notNull(url, ValuePool.UPLOAD_FAIL);
+                //使用内网上传的文件返回路径需要取消此路径才能访问到
+                url = url.replace("-internal", "");
                 urls.add(url);
             }
             return RestResponse.success(urls);
@@ -138,6 +140,8 @@ public class CommonController {
         try {
             String url = systemConfiguration.build().putObject(fileName, file.getBytes());
             log.info("upload file complete, file URL: {}", url);
+            //使用内网上传的文件返回路径需要取消此路径才能访问到
+            url = url.replace("-internal", "");
             return RestResponse.success(url);
         } catch (Exception e) {
             log.error("upload file occur exception", e);

+ 3 - 1
lift-business-service/src/main/resources/application-prod.yml

@@ -50,7 +50,9 @@ aliyun:
   # 外网地址 oss-cn-hangzhou-internal.aliyuncs.com
   # Bucket 域名 ty-oss-file.oss-cn-hangzhou-internal.aliyuncs.com 可以使用https://ty-oss-file.oss-cn-hangzhou-internal.aliyuncs.com
   oss:
-    endpoint: http://oss-cn-hangzhou.aliyuncs.com
+#    endpoint: http://oss-cn-hangzhou.aliyuncs.com
+    #使用内网需要把返回的路径 -internal去掉,不然外网无法访问
+    endpoint: http://oss-cn-hangzhou-internal.aliyuncs.com
     bucketName: ty-oss-file
     accessKeyId: LTAI4G1iLTczu8JxM2En57gY
     accessKeySecret: VHeRj3C2br87Uh447ruHsSTvYSDWeC