Postman 可以将文件作为路径中的变量吗? [英] Can Postman take a file as a variable from a path?

查看:15
本文介绍了Postman 可以将文件作为路径中的变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个邮递员集合,其中包含一组三个 API 调用,我想将它们链接在一起并使用 runner 函数提供一个数据文件.假设他们是:

I have a postman collection, with a set of three API calls I'd like to chain together and feed with a data file using the runner function. Lets say they're:

/prepareUpload

/上传

/confirmUpload

并且下一步需要每个输出.我很高兴从响应中提取内容并将它们放入变量中,为下一次调用做好准备,但我似乎遇到的一点是 /upload 需要一个 filefile 类型的 code> 参数,但 Postman 似乎不允许我将其设置为变量:

and the output of each is needed for the next step. I'm happily pulling stuff out of the responses and putting them into variables ready for the next call, but the bit I seem to be falling down on is the /upload needs a file parameter of type file, but Postman doesn't seem to let me set it to a variable:

我已尝试导出集合,手动编辑 json 以将其强制为变量并运行它,因此类似于:

I've tried exporting the collection, manually editing the json to force it to a variable and running that, so something like :

<snip>
    {
       "key": "file",
       "contentType": "{{contentType}}",
       "type": "file",
       "src": ["{{fullpath}}"]
    }
  ],
  "options": {
    "formdata": {}
}

其中 {{contentType}}{{fullpath}} 来自我的数据文件,但它似乎从未真正进行上传.

where {{contentType}} and {{fullpath}} are coming from my data file, but it never seems to actually do the upload.

有谁知道这是否可行?

推荐答案

好的,所以找到了这个问题的答案,简短的版本是 - Postman 做不到,但 Newman 可以:

Ok, so found the answer to this, and the short version is - Postman can't do it, but Newman can :

https://github.com/postmanlabs/newman#file-uploads

设置和运行它需要付出更多的努力,但它确实提供了一个自动化整个过程的解决方案.

It's a fair bit more effort to get it set up and working, but it does provide a solution for automating the whole process.

这篇关于Postman 可以将文件作为路径中的变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆