ljy121 преди 1 година
родител
ревизия
5018adc858

+ 2 - 15
zjugis-framework/zjugis-spring-boot-starter-file/src/main/java/com/zjugis/framework/file/core/client/s3/S3FileClient.java

@@ -92,31 +92,18 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
 
     @Override
     public String upload(byte[] content, String path, String type) throws Exception {
-        String objectName = generateUniqueFileName(path);
         // 执行上传
         client.putObject(PutObjectArgs.builder()
                 .bucket(config.getBucket()) // bucket 必须传递
                 .contentType(type)
-                .object(objectName) // 相对路径作为 key
+                .object(path) // 相对路径作为 key
                 .stream(new ByteArrayInputStream(content), content.length, -1) // 文件内容
                 .build());
         // 拼接返回路径
-        return config.getDomain() + "/" + objectName;
+        return config.getDomain() + "/" + path;
     }
 
 
-    private static String generateUniqueFileName(String path) {
-        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
-        int dotIndex = path.lastIndexOf('.');
-        if (dotIndex != -1) {
-            String name = path.substring(0, dotIndex);
-            String extension = path.substring(dotIndex);
-            return name + "_" + timeStamp + extension;
-        } else {
-            return path + "_" + timeStamp;
-        }
-    }
-
 
     @Override
     public void delete(String path) throws Exception {

+ 16 - 0
zjugis-module-infra/zjugis-module-infra-biz/src/main/java/com/zjugis/module/infra/service/file/FileServiceImpl.java

@@ -17,7 +17,10 @@ import org.jetbrains.annotations.NotNull;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.List;
+import java.util.Locale;
 import java.util.Set;
 
 import static com.zjugis.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -76,6 +79,7 @@ public class FileServiceImpl implements FileService {
         if (StrUtil.isEmpty(name)) {
             name = path;
         }
+        path = generateUniqueFileName(path);
 
         // 上传到文件存储器
         FileClient client = clientId == null? fileConfigService.getMasterFileClient():fileConfigService.getFileClient(clientId);
@@ -94,6 +98,18 @@ public class FileServiceImpl implements FileService {
         return file;
     }
 
+    private static String generateUniqueFileName(String path) {
+        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
+        int dotIndex = path.lastIndexOf('.');
+        if (dotIndex != -1) {
+            String name = path.substring(0, dotIndex);
+            String extension = path.substring(dotIndex);
+            return name + "_" + timeStamp + extension;
+        } else {
+            return path + "_" + timeStamp;
+        }
+    }
+
     @Override
     public void deleteFile(Long id) throws Exception {
         // 校验存在

+ 1 - 1
zjugis-module-infra/zjugis-module-infra-biz/src/main/resources/bootstrap-local.yaml

@@ -5,7 +5,7 @@ server:
 spring:
   cloud:
     inetutils:
-      preferred-networks: 10.10
+      preferred-networks: 10.10cre
     nacos:
       server-addr: 10.10.10.7:8848
       discovery: