From 93e114a4930ebf2c1d4b622e50966a6a1b04f979 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 24 May 2022 11:28:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dhttp=E5=8D=8F=E8=AE=AE=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=B8=BAbinary=E7=B1=BB=E5=9E=8B=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1013413 --user=赵勇 [接口测试]github#13849ES的api请求中有批量添加数据的方法,需要使用到binary的数据,上传一个文件,但是请求直接就报异常,找不到数据 https://www.tapd.cn/55049933/s/1162821 --- .../io/metersphere/api/dto/scenario/Body.java | 11 ++--- .../components/runtest/RunTestHTTPPage.vue | 45 +++++++++++++------ 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java b/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java index ea9613cbe7..38f31e3acc 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/Body.java @@ -97,7 +97,7 @@ public class Body { } else { try { if (StringUtils.isNotEmpty(this.getRaw())) { - JSONObject jsonObject = JSON.parseObject(this.getRaw(), Feature.OrderedField,Feature.DisableSpecialKeyDetect); + JSONObject jsonObject = JSON.parseObject(this.getRaw(), Feature.OrderedField, Feature.DisableSpecialKeyDetect); if (!this.getRaw().contains("$ref")) { jsonMockParse(jsonObject); } @@ -128,23 +128,24 @@ public class Body { List list = new ArrayList<>(); if (CollectionUtils.isNotEmpty(this.getKvs())) { this.getKvs().stream().filter(KeyValue::isFile).filter(KeyValue::isEnable).forEach(keyValue -> { - setFileArg(list, keyValue.getFiles(), keyValue, requestId); + setFileArg(list, keyValue.getFiles(), keyValue, requestId, false); }); } if (CollectionUtils.isNotEmpty(this.getBinary())) { this.getBinary().stream().filter(KeyValue::isFile).filter(KeyValue::isEnable).forEach(keyValue -> { - setFileArg(list, keyValue.getFiles(), keyValue, requestId); + setFileArg(list, keyValue.getFiles(), keyValue, requestId, true); }); } return list.toArray(new HTTPFileArg[0]); } - private void setFileArg(List list, List files, KeyValue keyValue, String requestId) { + private void setFileArg(List list, List files, + KeyValue keyValue, String requestId, boolean isBinary) { if (files != null) { files.forEach(file -> { String paramName = keyValue.getName() == null ? requestId : keyValue.getName(); String path = null; - if (StringUtils.isNotBlank(file.getId())) { + if (StringUtils.isNotBlank(file.getId()) && !isBinary) { // 旧数据 path = FileUtils.BODY_FILE_DIR + '/' + file.getId() + '_' + file.getName(); } else if (StringUtils.isNotBlank(this.tmpFilePath)) { diff --git a/frontend/src/business/components/api/definition/components/runtest/RunTestHTTPPage.vue b/frontend/src/business/components/api/definition/components/runtest/RunTestHTTPPage.vue index db76aca4ee..63c4bc4737 100644 --- a/frontend/src/business/components/api/definition/components/runtest/RunTestHTTPPage.vue +++ b/frontend/src/business/components/api/definition/components/runtest/RunTestHTTPPage.vue @@ -253,21 +253,38 @@ export default { apiCaseClose() { this.visible = false; }, - getBodyUploadFiles() { + getBodyUploadFiles(data) { let bodyUploadFiles = []; - this.api.bodyUploadIds = []; - let request = this.api.request; + data.bodyUploadIds = []; + let request = data.request; if (request.body) { - request.body.kvs.forEach(param => { - if (param.files) { - param.files.forEach(item => { - if (item.file) { - item.name = item.file.name; - bodyUploadFiles.push(item.file); - } - }); - } - }); + if (request.body.kvs) { + request.body.kvs.forEach(param => { + if (param.files) { + param.files.forEach(item => { + if (item.file) { + item.name = item.file.name; + bodyUploadFiles.push(item.file); + } + }); + } + }); + } + if (request.body.binary) { + request.body.binary.forEach(param => { + if (param.files) { + param.files.forEach(item => { + if (item.file) { + let fileId = getUUID().substring(0, 8); + item.name = item.file.name; + item.id = fileId; + data.bodyUploadIds.push(fileId); + bodyUploadFiles.push(item.file); + } + }); + } + }); + } } return bodyUploadFiles; }, @@ -305,7 +322,7 @@ export default { }, updateApi() { let url = "/api/definition/update"; - let bodyFiles = this.getBodyUploadFiles(); + let bodyFiles = this.getBodyUploadFiles(this.api); this.api.method = this.api.request.method; this.api.path = this.api.request.path; if (Object.prototype.toString.call(this.api.response).match(/\[object (\w+)\]/)[1].toLowerCase() !== 'object') {