Prechádzať zdrojové kódy

add
文件预上传接口

18339543638 6 mesiacov pred
rodič
commit
0090f320b1

+ 6 - 1
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/storage/controller/StorageFileController.java

@@ -56,5 +56,10 @@ public class StorageFileController {
         return CommonResult.success(fileService.obtainPreviewPath(recordId));
     }
 
-
+    @ApiOperationSupport(author = "lf",order = 5)
+    @PostMapping("/generationPreUploadUrl/{filename}")
+    @ApiOperation(value = "生成上传文件的预签名URL",notes = "权限:无")
+    public CommonResult<String> generationPreUploadUrl(@PathVariable("filename") String fileName){
+        return CommonResult.success(fileService.generationPreUploadUrl(fileName));
+    }
 }

+ 6 - 0
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/storage/service/IStorageFileService.java

@@ -62,4 +62,10 @@ public interface IStorageFileService {
     String obtainPreviewPath(String recordId) throws Exception;
 
     Map<String, StoragePojo> findStorageByIds(Collection<String> storageIds);
+
+    /**
+     * 生成预签名URL
+     * @return
+     */
+    String generationPreUploadUrl(String fileName);
 }

+ 14 - 0
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/storage/service/impl/StorageFileServiceImpl.java

@@ -174,6 +174,20 @@ public class StorageFileServiceImpl implements IStorageFileService {
                 .collect(Collectors.groupingBy(StoragePojo::getId,Collectors.collectingAndThen(Collectors.toList(),CollectionUtil::getFirst)));
     }
 
+    @Override
+    public String generationPreUploadUrl(String fileName) {
+        String configId=defaultConfig.getId();
+        FileClient fileClient = getClient(configId);
+        String preUploadUrl = fileClient.generationPreUploadUrl(createBizName(fileName));
+        SysStorageRecordDTO record;
+        record = SysStorageRecordDTO.builder()
+                .absolutePath(preUploadUrl)
+                .configId(configId)
+                .build();
+        storageRecordService.insertSysStorageRecordReturnId(record);
+        return preUploadUrl;
+    }
+
 
     private FileClient getClient(String id){
         FileClient fileClient = fileClientFactory.getFileClient(id);