fix(测试跟踪): 缺陷用例附件本地上传时, Content-Type报错问题

This commit is contained in:
song-cc-rock 2023-11-14 14:31:32 +08:00
parent 8b31d6a178
commit 989c8598bc
4 changed files with 23 additions and 31 deletions

View File

@ -1,7 +1,7 @@
import axios from 'axios' import axios from 'axios'
import {$error} from "./message" import {$error} from "./message"
import {getCurrentProjectID, getCurrentWorkspaceId} from "../utils/token"; 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 packageJSON from '@/../package.json'
import {getUrlParams, getUUID} from "../utils"; import {getUrlParams, getUUID} from "../utils";
import {initTaskData} from "../api/novice"; import {initTaskData} from "../api/novice";
@ -184,12 +184,12 @@ export function fileUploadWithProcessAndCancel(url, file, param, CancelTokenObj,
if (file) { if (file) {
formData.append("file", file); formData.append("file", file);
} }
formData.append('request', new Blob([JSON.stringify(param)], {type: "application/json"})); formData.append('sourceId', param);
let axiosRequestConfig = { let axiosRequestConfig = {
method: 'POST', method: 'POST',
url: url, url: url,
data: formData, data: formData,
headers: {'Content-Type': 'application/json;charset=UTF-8'}, headers: {'Content-Type': 'multipart/form-data'},
cancelToken: new CancelTokenObj(function executor(c) { cancelToken: new CancelTokenObj(function executor(c) {
cancelFileTokenList.push({"name": file.name, "cancelFunc": c}); cancelFileTokenList.push({"name": file.name, "cancelFunc": c});
}), }),

View File

@ -10,8 +10,9 @@ import io.metersphere.i18n.Translator;
import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.metadata.service.FileMetadataService; import io.metersphere.metadata.service.FileMetadataService;
import io.metersphere.request.attachment.AttachmentDumpRequest; import io.metersphere.request.attachment.AttachmentDumpRequest;
import io.metersphere.xpack.track.dto.AttachmentRequest;
import io.metersphere.service.AttachmentService; 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.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -20,7 +21,6 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import jakarta.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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) @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"}) @PostMapping(value = "/issue/upload", consumes = {"multipart/form-data"})
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_ISSUE_READ_EDIT) @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); 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) @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"}) @PostMapping(value = "/testcase/upload", consumes = {"multipart/form-data"})
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_CASE_READ_EDIT) @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); attachmentService.uploadAttachment(request, file);
} }

View File

@ -112,15 +112,11 @@
<script> <script>
import CaseAttachmentViewer from "@/business/case/components/case/CaseAttachmentViewer"; import CaseAttachmentViewer from "@/business/case/components/case/CaseAttachmentViewer";
import MsFileMetadataList from "../common/MsFileMetadataList"; import MsFileMetadataList from "../common/MsFileMetadataList";
import { TokenKey } from "metersphere-frontend/src/utils/constants"; import {TokenKey} from "metersphere-frontend/src/utils/constants";
import { import {byteToSize, getCurrentUser, getTypeByFileName, hasPermission,} from "@/business/utils/sdk-utils";
byteToSize,
getCurrentUser,
getTypeByFileName, hasPermission,
} from "@/business/utils/sdk-utils";
import axios from "axios"; import axios from "axios";
import { getUUID } from "metersphere-frontend/src/utils"; import {getUUID} from "metersphere-frontend/src/utils";
import { getCurrentProjectID } from "metersphere-frontend/src/utils/token"; import {getCurrentProjectID} from "metersphere-frontend/src/utils/token";
import { import {
attachmentList, attachmentList,
@ -244,7 +240,7 @@ export default {
async uploadFile(param, progressCallback) { async uploadFile(param, progressCallback) {
let progress = 0; let progress = 0;
let file = param.file; let file = param.file;
let data = { belongId: this.targetId, belongType: this.belongType }; let data = this.targetId;
let CancelToken = axios.CancelToken; let CancelToken = axios.CancelToken;
let self = this; let self = this;

View File

@ -337,28 +337,18 @@
import TemplateComponentEditHeader from "@/business/plan/view/comonents/report/TemplateComponentEditHeader"; import TemplateComponentEditHeader from "@/business/plan/view/comonents/report/TemplateComponentEditHeader";
import MsFormDivider from "metersphere-frontend/src/components/MsFormDivider"; import MsFormDivider from "metersphere-frontend/src/components/MsFormDivider";
import FormRichTextItem from "metersphere-frontend/src/components/FormRichTextItem"; import FormRichTextItem from "metersphere-frontend/src/components/FormRichTextItem";
import { import {buildCustomFields, parseCustomFieldForId,} from "metersphere-frontend/src/utils/custom_field";
buildCustomFields,
parseCustomFieldForId,
} from "metersphere-frontend/src/utils/custom_field";
import CustomFiledComponent from "metersphere-frontend/src/components/template/CustomFiledComponent"; import CustomFiledComponent from "metersphere-frontend/src/components/template/CustomFiledComponent";
import TestCaseIssueList from "@/business/issue/TestCaseIssueList"; import TestCaseIssueList from "@/business/issue/TestCaseIssueList";
import IssueEditDetail from "@/business/issue/IssueEditDetail"; import IssueEditDetail from "@/business/issue/IssueEditDetail";
import { import {byteToSize, getTypeByFileName, getUUID,} from "metersphere-frontend/src/utils";
byteToSize,
getTypeByFileName,
getUUID,
} from "metersphere-frontend/src/utils";
import { import {
getCurrentProjectID, getCurrentProjectID,
getCurrentUser, getCurrentUser,
getCurrentUserId, getCurrentUserId,
getCurrentWorkspaceId, getCurrentWorkspaceId,
} from "metersphere-frontend/src/utils/token"; } from "metersphere-frontend/src/utils/token";
import { import {hasLicense, hasPermission,} from "metersphere-frontend/src/utils/permission";
hasLicense,
hasPermission,
} from "metersphere-frontend/src/utils/permission";
import { import {
enableThirdPartTemplate, enableThirdPartTemplate,
getComments, getComments,
@ -383,7 +373,7 @@ import CustomFiledFormItem from "metersphere-frontend/src/components/form/Custom
import MsMarkDownText from "metersphere-frontend/src/components/MsMarkDownText"; import MsMarkDownText from "metersphere-frontend/src/components/MsMarkDownText";
import IssueComment from "@/business/issue/IssueComment"; import IssueComment from "@/business/issue/IssueComment";
import ReviewCommentItem from "@/business/review/commom/ReviewCommentItem"; import ReviewCommentItem from "@/business/review/commom/ReviewCommentItem";
import { TokenKey } from "metersphere-frontend/src/utils/constants"; import {TokenKey} from "metersphere-frontend/src/utils/constants";
import TestCaseAttachment from "@/business/case/components/TestCaseAttachment"; import TestCaseAttachment from "@/business/case/components/TestCaseAttachment";
import axios from "axios"; import axios from "axios";
import MsFileMetadataList from "metersphere-frontend/src/components/environment/commons/variable/QuoteFileList"; import MsFileMetadataList from "metersphere-frontend/src/components/environment/commons/variable/QuoteFileList";
@ -912,7 +902,7 @@ export default {
async uploadFile(param, progressCallback) { async uploadFile(param, progressCallback) {
let progress = 0; let progress = 0;
let file = param.file; let file = param.file;
let data = { belongId: this.issueId, belongType: "issue" }; let data = this.issueId;
let CancelToken = axios.CancelToken; let CancelToken = axios.CancelToken;
let self = this; let self = this;
uploadIssueAttachment( uploadIssueAttachment(