postman - Postman 可以将文件作为路径中的变量吗?

标签 postman postman-collection-runner

我有一个 postman 集合,我想将一组三个 API 调用链接在一起,并使用 runner 函数提供数据文件。可以说他们是:/prepareUpload/upload/confirmUpload并且下一步需要每个的输出。我很高兴地从响应中提取内容并将它们放入准备好下一次调用的变量中,但我似乎陷入困境的是 /upload需要一个 file类型参数 file ,但 postman 似乎不让我将其设置为变量:
enter image description here
我尝试导出集合,手动编辑 json 以将其强制为变量并运行它,例如:

<snip>
    {
       "key": "file",
       "contentType": "{{contentType}}",
       "type": "file",
       "src": ["{{fullpath}}"]
    }
  ],
  "options": {
    "formdata": {}
}
哪里{{contentType}}{{fullpath}}来自我的数据文件,但似乎从未真正进行上传。
有谁知道这是否可能?

最佳答案

问题:
在 postman 中,如果我们检查 UI,我们会注意到无法将文件路径定义为变量。
enter image description here
当我们需要从不同系统运行文件时,这看起来像是一个限制
解决方案:
解决方案是破解 collection.json 文件。打开 json 并编辑 formdata src 并将其替换为变量,例如 fire_path :{{fire_path}}
enter image description here
现在在 postman :
在预请求中,您可以在下面的代码中设置路径
pm.environment.set("file_path","C:/Users/guest/Desktop/1.png")
您也可以直接将其保存为环境变量,或者在使用 newman 时使用 --env-var 通过 cmd 传递。
注:
将外部工作目录的访问文件设置为 true(右上角的设置)
enter image description here

关于postman - Postman 可以将文件作为路径中的变量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63121276/

相关文章:

java - 如何从 Spring 环境自动生成 postman 集合

Postman - 仅在多个请求*多次迭代的情况下执行第一次迭代的第一个请求

postman - 如何循环遍历 Postman Collection Runner 中数据文件中的每一行然后输出到文件中

postman - 在 Postman 中,如何使用 collection runner POST 二进制文件

postman 动态取消设置环境变量

postman - postman 中的授权不记名 token

rest - JSON 错误 |无数据,1 处输入为空 :1

java - HTTP 405 不支持请求方法 'PUT'

azure - 如何根据用户邮件 ID 获取特定订阅中的用户角色

node.js - 标识符...已经声明