From 989c8598bcde9a0c9640b4692799ff3757b12228 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Tue, 14 Nov 2023 14:31:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E7=BC=BA=E9=99=B7=E7=94=A8=E4=BE=8B=E9=99=84=E4=BB=B6=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E4=B8=8A=E4=BC=A0=E6=97=B6,=20Content-Type=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frontend/src/plugins/request.js | 6 +++--- .../controller/AttachmentController.java | 14 +++++++++---- .../case/CaseAttachmentComponent.vue | 14 +++++-------- .../src/business/issue/IssueEditDetail.vue | 20 +++++-------------- 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/framework/sdk-parent/frontend/src/plugins/request.js b/framework/sdk-parent/frontend/src/plugins/request.js index 744b7e59f4..c6c832cd1d 100644 --- a/framework/sdk-parent/frontend/src/plugins/request.js +++ b/framework/sdk-parent/frontend/src/plugins/request.js @@ -1,7 +1,7 @@ import axios from 'axios' import {$error} from "./message" import {getCurrentProjectID, getCurrentWorkspaceId} from "../utils/token"; -import {PROJECT_ID, TokenKey, WORKSPACE_ID, TASK_PATH, TASK_DATA} from "../utils/constants"; +import {PROJECT_ID, TASK_PATH, TokenKey, WORKSPACE_ID} from "../utils/constants"; import packageJSON from '@/../package.json' import {getUrlParams, getUUID} from "../utils"; import {initTaskData} from "../api/novice"; @@ -184,12 +184,12 @@ export function fileUploadWithProcessAndCancel(url, file, param, CancelTokenObj, if (file) { formData.append("file", file); } - formData.append('request', new Blob([JSON.stringify(param)], {type: "application/json"})); + formData.append('sourceId', param); let axiosRequestConfig = { method: 'POST', url: url, data: formData, - headers: {'Content-Type': 'application/json;charset=UTF-8'}, + headers: {'Content-Type': 'multipart/form-data'}, cancelToken: new CancelTokenObj(function executor(c) { cancelFileTokenList.push({"name": file.name, "cancelFunc": c}); }), diff --git a/test-track/backend/src/main/java/io/metersphere/controller/AttachmentController.java b/test-track/backend/src/main/java/io/metersphere/controller/AttachmentController.java index 097905f70e..dbc2cd48bc 100644 --- a/test-track/backend/src/main/java/io/metersphere/controller/AttachmentController.java +++ b/test-track/backend/src/main/java/io/metersphere/controller/AttachmentController.java @@ -10,8 +10,9 @@ import io.metersphere.i18n.Translator; import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.metadata.service.FileMetadataService; import io.metersphere.request.attachment.AttachmentDumpRequest; -import io.metersphere.xpack.track.dto.AttachmentRequest; import io.metersphere.service.AttachmentService; +import io.metersphere.xpack.track.dto.AttachmentRequest; +import jakarta.annotation.Resource; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.http.HttpHeaders; @@ -20,7 +21,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import jakarta.annotation.Resource; import java.util.ArrayList; import java.util.List; @@ -39,14 +39,20 @@ public class AttachmentController { @MsAuditLog(module = OperLogModule.TRACK_BUG, type = OperLogConstants.UPDATE, content = "#msClass.getLogDetails(#request.belongId, #request.belongType, #file.getOriginalFilename(), false)", msClass = AttachmentService.class) @PostMapping(value = "/issue/upload", consumes = {"multipart/form-data"}) @RequiresPermissions(PermissionConstants.PROJECT_TRACK_ISSUE_READ_EDIT) - public void uploadIssueAttachment(@RequestPart("request") AttachmentRequest request, @RequestPart(value = "file", required = false) MultipartFile file) { + public void uploadIssueAttachment(@RequestParam(value = "sourceId") String belongId, @RequestParam(value = "file") MultipartFile file) { + AttachmentRequest request = new AttachmentRequest(); + request.setBelongId(belongId); + request.setBelongType(AttachmentType.ISSUE.type()); attachmentService.uploadAttachment(request, file); } @MsAuditLog(module = OperLogModule.TRACK_TEST_CASE, type = OperLogConstants.UPDATE, content = "#msClass.getLogDetails(#request.belongId, #request.belongType, #file.getOriginalFilename(), false)", msClass = AttachmentService.class) @PostMapping(value = "/testcase/upload", consumes = {"multipart/form-data"}) @RequiresPermissions(PermissionConstants.PROJECT_TRACK_CASE_READ_EDIT) - public void uploadTestCaseAttachment(@RequestPart("request") AttachmentRequest request, @RequestPart(value = "file", required = false) MultipartFile file) { + public void uploadTestCaseAttachment(@RequestParam(value = "sourceId") String belongId, @RequestParam(value = "file") MultipartFile file) { + AttachmentRequest request = new AttachmentRequest(); + request.setBelongId(belongId); + request.setBelongType(AttachmentType.TEST_CASE.type()); attachmentService.uploadAttachment(request, file); } diff --git a/test-track/frontend/src/business/case/components/case/CaseAttachmentComponent.vue b/test-track/frontend/src/business/case/components/case/CaseAttachmentComponent.vue index f93d25b4dd..4d4da9cfb3 100644 --- a/test-track/frontend/src/business/case/components/case/CaseAttachmentComponent.vue +++ b/test-track/frontend/src/business/case/components/case/CaseAttachmentComponent.vue @@ -112,15 +112,11 @@