我遇到了Postman / Node.js的问题,就像我尝试使用附加文档的POST方法一样。我想在请求之前更改文件的名称,因为无法上载两个同名文件。我希望能够进行设置,以便我的学院可以随时运行一个集合。我从http://blog.getpostman.com/2017/09/21/run-collections-with-file-uploads-using-newman/为Postman做了一个解决方法,用于文件上传自动化。
我的问题是:
如何获取文件,将其名称更改为随机的名称,例如test {{$ timestamp}}。docx并再次指向该.json文件中的新名称,以便可以上传?
这是我的.json文件
{
"name": "Save case's documents CID CDN",
"event": [
{
"listen": "test",
"script": {
"id": "04bf1f30-c2bc-4250-97c9-9efb7afa25e3",
"type": "text/javascript",
"exec": [
"// Check the status of a request",
"pm.test(\"Addition of a document successful!\", function () {",
" pm.response.to.have.status(200);",
"});",
"// Check the response time ",
"pm.test(\"Response time is acceptable\", function () {",
" pm.expect(pm.response.responseTime).to.be.below(2000);",
"});",
"// Set documentName variable",
"var jsonData = JSON.parse(responseBody);",
"postman.setEnvironmentVariable(\"documentName\", jsonData.content.documentName);"
]
}
},
{
"listen": "prerequest",
"script": {
"id": "09a922cd-6c2a-47cb-b597-d5dcab0d45bd",
"type": "text/javascript",
"exec": [
"",
""
]
}
}
],
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "",
"type": "string"
}
]
},
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "{{token}}"
},
{
"key": "Content-Type",
"value": "application/x-www-form-urlencoded"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "document",
"value":
"C:\\Users\\User123456\\Desktop\\test.docx",
"description": "",
"type": "file",
"src": "C:\\Users\\User123456\\Desktop\\test.docx"
},
{
"key": "documentCategory",
"value": "Other",
"description": "",
"type": "text"
},
{
"key": "refCreatedBy",
"value": "{{bu_id}}",
"description": "",
"type": "text"
},
{
"key": "createdAt",
"value": "{{date}}",
"description": "",
"type": "text"
},
{
"key": "accuracy.status",
"value": "string",
"description": "",
"type": "text"
},
{
"key": "accuracy.lastModifiedDate",
"value": "{{$timestamp}}",
"description": "",
"type": "text"
},
{
"key": "accuracy.lastModifiedBy",
"value": "{{bu_id}}",
"description": "",
"type": "text"
},
{
"key": "quality.status",
"value": "sting",
"description": "",
"type": "text"
},
{
"key": "quality.lastModifiedDate",
"value": "{{$timestamp}}",
"description": "",
"type": "text"
},
{
"key": "quality.lastModifiedBy",
"value": "{{$timestamp}}",
"description": "",
"type": "text"
}
]
},
"url": {
"raw": "{{site}}/cases/{{case_id}}/documents/{{documentName}}",
"host": [
"{{site}}"
],
"path": [
"cases",
"{{case_id}}",
"documents",
"{{documentName}}"
]
},
"description": ""
},
"response": []
}
]
}