diff --git a/backend/framework/sdk/src/main/resources/i18n/project.properties b/backend/framework/sdk/src/main/resources/i18n/project.properties index cccea5fbf7..40780c1bd3 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project.properties @@ -456,6 +456,8 @@ file.log.association.update=更新了关联了文件 file.log.association.delete=取消关联了文件 file.log.transfer.association=转存并关联了文件 file.name.cannot.be.empty=文件名称不能为空 +file.size.is.too.large=文件过大 +file.is.empty=文件为空 file.name.error=文件名不合法 #file management over diff --git a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties index 0e6b2d55d1..caa6b43eb8 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties @@ -492,6 +492,8 @@ file.log.association.update=updated file file.log.association.delete=delete file file.log.transfer.association=transfer and association file file.name.cannot.be.empty=File name cannot be empty +file.size.is.too.large=File is too large +file.is.empty=File is empty file.name.error=File name error #file management over diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties index bf3164ad05..334408f134 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties @@ -491,6 +491,8 @@ file.log.association.update=更新了关联了文件 file.log.association.delete=取消关联了文件 file.log.transfer.association=转存并关联了文件 file.name.cannot.be.empty=文件名称不能为空 +file.size.is.too.large=文件过大 +file.is.empty=文件为空 file.name.error=文件名不合法 #file management over # template diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties index b7a804cc57..15b88de2bd 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties @@ -492,6 +492,8 @@ file.log.association.update=更新了關聯了文件 file.log.association.delete=取消關聯了文件 file.log.transfer.association=轉存並關聯了文件 file.name.cannot.be.empty=文件名稱不能為空 +file.size.is.too.large=文件過大 +file.is.empty=文件為空 file.name.error=文件名不合法 #file management over diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java index 8b96bf3f62..18ec4bcede 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java @@ -71,6 +71,8 @@ public class FileMetadataService { private FileService fileService; @Value("${metersphere.file.batch-download-max:600MB}") + private DataSize batchDownloadMaxSize; + @Value("50MB") private DataSize maxFileSize; public FileMetadata selectById(String id) { @@ -123,6 +125,9 @@ public class FileMetadataService { } public FileMetadata genFileMetadata(String filePath, String storage, long size, boolean enable, String projectId, String moduleId, String operator) { + if (size > maxFileSize.toBytes()) { + throw new MSException(Translator.get("file.size.is.too.large")); + } String fileName = TempFileUtils.getFileNameByPath(filePath); FileMetadata fileMetadata = new FileMetadata(); if (StringUtils.lastIndexOf(fileName, ".") > 0) { @@ -401,11 +406,11 @@ public class FileMetadataService { } if (fileSize.get() == 0) { - throw new MSException(Translator.get("file.size.is.zero")); + throw new MSException(Translator.get("file.is.empty")); } DataSize dataSize = DataSize.ofBytes(fileSize.get()); - if (maxFileSize.compareTo(dataSize) < 0) { + if (batchDownloadMaxSize.compareTo(dataSize) < 0) { throw new MSException(Translator.get("file.size.is.too.large")); } } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java index 7a5fd025c3..49edc6764c 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java @@ -573,6 +573,17 @@ public class FileManagementControllerTests extends BaseTest { paramMap.add("request", JSON.toJSONString(fileUploadRequest)); this.requestMultipart(FileManagementRequestUtils.URL_FILE_UPLOAD, paramMap).andExpect(status().is5xxServerError()); + //上传大于50M的文件 + filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/largeFile.zip")).getPath(); + file = new MockMultipartFile("file", "largeFile.zip", MediaType.APPLICATION_OCTET_STREAM_VALUE, FileManagementBaseUtils.getFileBytes(filePath)); + fileUploadRequest = new FileUploadRequest(); + fileUploadRequest.setProjectId(project.getId()); + fileUploadRequest.setModuleId(ModuleConstants.DEFAULT_NODE_ID); + paramMap = new LinkedMultiValueMap<>(); + paramMap.add("file", file); + paramMap.add("request", JSON.toJSONString(fileUploadRequest)); + + this.requestMultipart(FileManagementRequestUtils.URL_FILE_UPLOAD, paramMap).andExpect(status().is5xxServerError()); } @Test diff --git a/backend/services/project-management/src/test/resources/file/largeFile.zip b/backend/services/project-management/src/test/resources/file/largeFile.zip new file mode 100644 index 0000000000..8dd88b8c12 Binary files /dev/null and b/backend/services/project-management/src/test/resources/file/largeFile.zip differ