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 5b91fd8b54..5c02faa3d4 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 @@ -480,7 +480,9 @@ public class FileMetadataService { public ResponseEntity downloadPreviewImgById(String id) throws Exception { FileMetadata fileMetadata = fileMetadataMapper.selectByPrimaryKey(id); String previewImgPath = null; - if (TempFileUtils.isImage(fileMetadata.getType())) { + if (StringUtils.equalsIgnoreCase(fileMetadata.getType(), "svg")) { + return this.downloadById(id); + } else if (TempFileUtils.isImage(fileMetadata.getType())) { if (TempFileUtils.isImgPreviewFileExists(fileMetadata.getId())) { previewImgPath = TempFileUtils.getPreviewImgFilePath(fileMetadata.getId()); } else { 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 5bd5152748..094206b434 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 @@ -440,6 +440,17 @@ public class FileManagementControllerTests extends BaseTest { fileUploadRequest.setEnable(false); //小型图片文件,用于测试预览图下载 + filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/icon_file-unknow_colorful.svg")).getPath(); + file = new MockMultipartFile("file", "icon_file-unknow_colorful.svg", MediaType.APPLICATION_OCTET_STREAM_VALUE, FileManagementBaseUtils.getFileBytes(filePath)); + paramMap = new LinkedMultiValueMap<>(); + paramMap.add("file", file); + paramMap.add("request", JSON.toJSONString(fileUploadRequest)); + mvcResult = this.requestMultipartWithOkAndReturn(FileManagementRequestUtils.URL_FILE_UPLOAD, paramMap); + returnId = JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData().toString(); + checkLog(returnId, OperationLogType.ADD, FileManagementRequestUtils.URL_FILE_UPLOAD); + FILE_ID_PATH.put(returnId, filePath); + + //svg文件,用于测试预览图下载 filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/1182937072541700.jpg")).getPath(); file = new MockMultipartFile("file", "1182937072541700.jpg", MediaType.APPLICATION_OCTET_STREAM_VALUE, FileManagementBaseUtils.getFileBytes(filePath)); paramMap = new LinkedMultiValueMap<>(); @@ -449,6 +460,7 @@ public class FileManagementControllerTests extends BaseTest { returnId = JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData().toString(); checkLog(returnId, OperationLogType.ADD, FileManagementRequestUtils.URL_FILE_UPLOAD); FILE_ID_PATH.put(returnId, filePath); + uploadedFileTypes.add("svg"); //检查文件类型获取接口有没有获取到数据 fileTypes = this.getFileType(); diff --git a/backend/services/project-management/src/test/resources/file/icon_file-unknow_colorful.svg b/backend/services/project-management/src/test/resources/file/icon_file-unknow_colorful.svg new file mode 100644 index 0000000000..fcb6ac391b --- /dev/null +++ b/backend/services/project-management/src/test/resources/file/icon_file-unknow_colorful.svg @@ -0,0 +1,10 @@ + + + + + + + + + +