From ba501f32cb1e7d45339dbd5d85015f205a75de42 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Wed, 24 Nov 2021 14:21:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20markDown=E9=83=A8=E5=88=86=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=B8=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/request/MdUploadRequest.java | 1 + .../java/io/metersphere/service/ResourceService.java | 12 ++++++++++-- .../components/settings/personal/JiraUserInfo.vue | 2 +- .../settings/workspace/components/JiraSetting.vue | 2 +- .../track/case/components/FormRichTextItem.vue | 4 +++- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/io/metersphere/controller/request/MdUploadRequest.java b/backend/src/main/java/io/metersphere/controller/request/MdUploadRequest.java index de2609fdcd..d91500bbb1 100644 --- a/backend/src/main/java/io/metersphere/controller/request/MdUploadRequest.java +++ b/backend/src/main/java/io/metersphere/controller/request/MdUploadRequest.java @@ -7,4 +7,5 @@ import lombok.Setter; @Setter public class MdUploadRequest { private String id; + private String fileName; } diff --git a/backend/src/main/java/io/metersphere/service/ResourceService.java b/backend/src/main/java/io/metersphere/service/ResourceService.java index 5bd34eb452..ebe96360dd 100644 --- a/backend/src/main/java/io/metersphere/service/ResourceService.java +++ b/backend/src/main/java/io/metersphere/service/ResourceService.java @@ -11,6 +11,8 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import java.io.File; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.Date; @Service @@ -18,14 +20,20 @@ import java.util.Date; public class ResourceService { public void mdUpload(MdUploadRequest request, MultipartFile file) { - FileUtils.uploadFile(file, FileUtils.MD_IMAGE_DIR, request.getId() + "_" + file.getOriginalFilename()); + FileUtils.uploadFile(file, FileUtils.MD_IMAGE_DIR, request.getId() + "_" + request.getFileName()); } public ResponseEntity getMdImage(String name) { File file = new File(FileUtils.MD_IMAGE_DIR + "/" + name); HttpHeaders headers = new HttpHeaders(); + String fileName = ""; + try { + fileName = URLEncoder.encode(file.getName(), "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); - headers.add("Content-Disposition", "attachment; filename=" + file.getName()); + headers.add("Content-Disposition", "attachment; filename=" + fileName); headers.add("Pragma", "no-cache"); headers.add("Expires", "0"); headers.add("Last-Modified", new Date().toString()); diff --git a/frontend/src/business/components/settings/personal/JiraUserInfo.vue b/frontend/src/business/components/settings/personal/JiraUserInfo.vue index 44e20cab6e..372cc66b8d 100644 --- a/frontend/src/business/components/settings/personal/JiraUserInfo.vue +++ b/frontend/src/business/components/settings/personal/JiraUserInfo.vue @@ -6,7 +6,7 @@ - + diff --git a/frontend/src/business/components/settings/workspace/components/JiraSetting.vue b/frontend/src/business/components/settings/workspace/components/JiraSetting.vue index af911edfe0..06d6a030c2 100644 --- a/frontend/src/business/components/settings/workspace/components/JiraSetting.vue +++ b/frontend/src/business/components/settings/workspace/components/JiraSetting.vue @@ -6,7 +6,7 @@ - + diff --git a/frontend/src/business/components/track/case/components/FormRichTextItem.vue b/frontend/src/business/components/track/case/components/FormRichTextItem.vue index c222fab3c8..7856841fa4 100644 --- a/frontend/src/business/components/track/case/components/FormRichTextItem.vue +++ b/frontend/src/business/components/track/case/components/FormRichTextItem.vue @@ -107,9 +107,11 @@ export default { }; file.prefix = param.id; this.result.loading = true; + // 带括号和空格,可能无法展示 + param.fileName = file.name.replace("(", "").replace(")", "").replace(" ", ""); this.$fileUpload('/resource/md/upload', file, null, param, () => { this.$success(this.$t('commons.save_success')); - this.$refs.md.$img2Url(pos, '/resource/md/get/' + param.id + '_' + file.name); + this.$refs.md.$img2Url(pos, '/resource/md/get/' + param.id + '_' + param.fileName); this.result.loading = false; }); this.$emit('imgAdd', file);