# Form-data images with iteration data variables

**URL:** <https://community.postman.com/t/form-data-images-with-iteration-data-variables/7987>\
**Category:** Help Hub\
**Tags:** newman-project\
**Created:** [September 25, 2019, 2:44pm UTC](https://community.postman.com/t/form-data-images-with-iteration-data-variables/7987 "2019-09-25T14:44:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![marc.vantveer](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/marc.vantveer/32/2884_2.png) [@marc.vantveer](https://community.postman.com/u/marc.vantveer)\
**Post date:** [September 25, 2019, 2:44pm UTC](https://community.postman.com/t/form-data-images-with-iteration-data-variables/7987/1 "2019-09-25T14:44:45Z")

</div>

> **Archived topic — this may be out of date.**  
> Newman has been replaced by the **[Postman CLI](https://learning.postman.com/docs/postman-cli/postman-cli-overview/)**, Postman’s official, signed command-line tool. It runs collections as Newman did, and also lints API specs, runs mocks and monitors, and syncs local files with Postman from your terminal, CI/CD pipeline or coding agent.  
> Working with an AI coding agent? The [Postman plugin](https://github.com/postmanlabs/postman-plugin) lets agents in Claude Code, Cursor, Codex and others design, mock, test and ship APIs with Postman.  
> For current help, see the [Postman docs](https://learning.postman.com/docs/), try the free [Postman tools](https://www.postman.com/tools) (no account needed), or join us on [Discord](https://discord.gg/58aNNsRBGR).

I like to use newman with a images as POST data in the body for form-data. I can update upload an image but I like to run over multiple images as iterations.  
How can I make the form-data variable like {{image}} as file place holder and then link it to a local folder when using it with Newman?

---

<div class="post-metadata">

**Author:** ![postman-kyle](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@postman-kyle](https://community.postman.com/u/postman-kyle)\
**Post date:** [September 30, 2019, 10:40pm UTC](https://community.postman.com/t/form-data-images-with-iteration-data-variables/7987/2 "2019-09-30T22:40:52Z")

</div>

I am still digging up a way to do this.

But here is a good way to start:

> **[GitHub - postmanlabs/newman: Newman is a command-line collection runner for...](https://github.com/postmanlabs/newman#file-uploads)**
>
> Newman is a command-line collection runner for Postman

Newman can be imported like any other NodeJS module.

Right now I’m investigating if we can add a variable like `{{foo}}` into src and be able to iterate over each one using `iterationData`

However, I can’t get clear confirmation just yet, I’ll post a more detailed answer after I get some feedback.

You can also set src in the formdata of the collection as an array of data types, but I don’t believe that’ll set off multiple requests instead of one large request.

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [September 30, 2019, 11:40pm UTC](https://community.postman.com/t/form-data-images-with-iteration-data-variables/7987/3 "2019-09-30T23:40:08Z")

</div>

@marc.vantveer & @postman-kyle

This is actually possible. Just export your collection once and replace the src property with a Postman variable. Reimport the collection in Postman and you are ready to go.

---

<div class="post-metadata">

**Author:** ![postman-kyle](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@postman-kyle](https://community.postman.com/u/postman-kyle)\
**Post date:** [September 30, 2019, 11:58pm UTC](https://community.postman.com/t/form-data-images-with-iteration-data-variables/7987/4 "2019-09-30T23:58:29Z")

</div>

Haha I sent a HUGE message to vivek about this so let me just copy again here:

Could you help me read this object? I am reading the summary.run.executions.request.formdata I want to be able to iterate over files in the local directory in newman and send requests sending each file. I currently don’t see if this can be done as the UI in the Postman App only allows me to upload a document and not add a variable.

```
My node script with newman as a library:
        newman.run({
          collection: c,
          iterationData: [{ "variable": "./Chris.png"}, {"variable": "./abinav.png"}],
        }).on('iteration', function (err, args) { // on start of run, log to console
            console.log('starting an iteration...');
        }).on('done', function (err, summary) {
            if (err || summary.error) {
                console.error('collection run encountered an error.');
            }
            else {
                console.log('collection run completed.');
              // console.log(summary.run.stats);
              summary.run.executions.forEach( item => console.log(item.request.body.formdata) );
            }
        });
        my collection with variable in the formdata:
            "body": {
                "mode": "formdata",
                    "formdata": [
                    {
                    "key": "img",
                    "type": "file",
                    "src": "{{variable}}",
                                 "disabled": true
                      }
                     ]

```

The response I get when I try to see the formdata and if {{variable}} actually populated.

> ```
> > PostmanPropertyList {
> > members:
> > [ PostmanFormParam {
> > disabled: true,
> > key: 'img',
> > value: '',
> > type: 'file',
> > src: './Chris.png',
> > contentType: undefined } ],
> > reference:
> > { img:
> > PostmanFormParam {
> > disabled: true,
> > key: 'img',
> > value: '',
> > type: 'file',
> > src: './Chris.png',
> > contentType: undefined } },
> > Type:
> > { ... },
> > _postman_listIndexKey: 'key',
> > _postman_listAllowsMultipleValues: true }
> > PostmanPropertyList {
> > members:
> > [ PostmanFormParam {
> > disabled: true,
> > key: 'img',
> > value: '',
> > type: 'file',
> > src: './abinav.png',
> > contentType: undefined } ],
> > reference:
> > { img:
> > PostmanFormParam {
> > disabled: true,
> > key: 'img',
> > value: '',
> > type: 'file',
> > src: './abinav.png',
> > contentType: undefined } },
> > Type:
> > ...
> 
> ```

**I can’t determine if the response I’m getting back is successfully parsing the {{variable}} with the iterationData, I don’t know the difference from members and reference in the output object**

---

<div class="post-metadata">

**Author:** ![marc.vantveer](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/marc.vantveer/32/2884_2.png) [@marc.vantveer](https://community.postman.com/u/marc.vantveer)\
**Post date:** [October 1, 2019, 8:55am UTC](https://community.postman.com/t/form-data-images-with-iteration-data-variables/7987/5 "2019-10-01T08:55:07Z")

</div>

Hi Kyle,

This is the js script I’m now building:

```auto
const newman = require('newman'); // require newman in your project

// call newman.run to pass `options` object and wait for callback
newman.run({
    collection: "/Users/marc/Desktop/Image Recognition copy.postman_collection.json",
    iterationData: [{ "variable": "/Users/marc/Desktop/bolt.jpg"}, {"variable": "/Users/marc/Desktop/hammer.png"}],
    reporters: 'cli'
}, function (err) {
    if (err) { throw err; }
    console.log('collection run complete!');
});

```

And this is the collection:

And the error is:

┌

│ 'Form param `image`, file load error: “{{image}}”, no

│ such file’

└

Met vriendelijke groet,

Marc van ’t Veer

* * *

**Polteq**

* * *

Mobile test expert

+31 (0) 33 - 277 35 22

+31 (0) 6 - 18 35 41 34

[marc.vantveer@polteq.com](mailto:marc.vantveer@polteq.com)

www.polteq.com

**Passion for testing** \*\* **. \*\*\*\* Be  
an example to others**.\*\*

* * *

Amersfoort Amsterdam Deventer Eindhoven Groningen Rotterdam Leuven (BE)

(Attachment Image Recognition copy.postman\_collection.json is missing)

---

<div class="post-metadata">

**Author:** ![marc.vantveer](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/marc.vantveer/32/2884_2.png) [@marc.vantveer](https://community.postman.com/u/marc.vantveer)\
**Post date:** [October 1, 2019, 8:56am UTC](https://community.postman.com/t/form-data-images-with-iteration-data-variables/7987/6 "2019-10-01T08:56:32Z")

</div>

Hi Kyle,

This is the js script I’m now building:

```auto
const newman = require('newman'); // require newman in your project

// call newman.run to pass `options` object and wait for callback
newman.run({
    collection: "/Users/marc/Desktop/Image Recognition copy.postman_collection.json",
    iterationData: [{ "variable": "/Users/marc/Desktop/bolt.jpg"}, {"variable": "/Users/marc/Desktop/hammer.png"}],
    reporters: 'cli'
}, function (err) {
    if (err) { throw err; }
    console.log('collection run complete!');
});

```

And this is the collection:

And the error is:

┌

│ 'Form param `image`, file load error: “{{image}}”, no

│ such file’

└

Met vriendelijke groet,

Marc van ’t Veer

* * *

**Polteq**

* * *

Mobile test expert

+31 (0) 33 - 277 35 22

+31 (0) 6 - 18 35 41 34

[marc.vantveer@polteq.com](mailto:marc.vantveer@polteq.com)

> **[Polteq, specialist in software testen](https://www.polteq.com)**
>
> Verhogen van software kwaliteit, dat is wat Polteq als specialist in software testen al meer dan 20 jaar doet.

**Passion for testing** \*\* **. \*\*\*\* Be  
an example to others**.\*\*

* * *

Amersfoort Amsterdam Deventer Eindhoven Groningen Rotterdam Leuven (BE)

(Attachment Image Recognition copy.postman\_collection.txt is missing)

---

<div class="post-metadata">

**Author:** ![postman-kyle](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@postman-kyle](https://community.postman.com/u/postman-kyle)\
**Post date:** [October 3, 2019, 5:15pm UTC](https://community.postman.com/t/form-data-images-with-iteration-data-variables/7987/7 "2019-10-03T17:15:00Z")

</div>

Hi Marc,

In this code you have `variable` in itertationData.  
You need to change that to `image` as that’s your template-variable name, `{{image}}`

```
const newman = require('newman'); // require newman in your project

// call newman.run to pass `options` object and wait for callback
newman.run({
    collection: "/Users/marc/Desktop/Image Recognition copy.postman_collection.json",
    iterationData: [{ "variable": "/Users/marc/Desktop/bolt.jpg"}, {"variable": "/Users/marc/Desktop/hammer.png"}],
    reporters: 'cli'
}, function (err) {
    if (err) { throw err; }
    console.log('collection run complete!');
});

```

I just confirmed this works.

Basically the `collection.json` just needs to have a variable and the runtime should update the data.

---

<div class="post-metadata">

**Author:** ![marc.vantveer](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/marc.vantveer/32/2884_2.png) [@marc.vantveer](https://community.postman.com/u/marc.vantveer)\
**Post date:** [October 3, 2019, 7:22pm UTC](https://community.postman.com/t/form-data-images-with-iteration-data-variables/7987/8 "2019-10-03T19:22:11Z")

</div>

Hi Kyle,

Thank you for your answer and it works. This was not an easy puzzle to grasp. The only thing that is still wondering is the following:

```auto
<img apple-inline="yes" id="AB7EFD0A-2661-4962-9CF8-D69766326CC5" src="cid:35BCB0E6-1019-4900-9EFA-5B62AD9EBA84@dynamic.ziggo.nl" class="">

```

The input file into newman is an input file (json or cvs). Is it also possible to assign a folder within the folder image variables?

Met vriendelijke groet,

Marc van ’t Veer

* * *

**Polteq**

* * *

Mobile test expert

+31 (0) 33 - 277 35 22

+31 (0) 6 - 18 35 41 34

[marc.vantveer@polteq.com](mailto:marc.vantveer@polteq.com)

www.polteq.com

**Passion for testing** \*\* **. \*\*\*\* Be  
an example to others**.\*\*

* * *

Amersfoort Amsterdam Deventer Eindhoven Groningen Rotterdam Leuven (BE)

(Attachment GeplakteAfbeelding-1.tiff is missing)

---

<div class="post-metadata">

**Author:** ![postman-kyle](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@postman-kyle](https://community.postman.com/u/postman-kyle)\
**Post date:** [October 3, 2019, 9:43pm UTC](https://community.postman.com/t/form-data-images-with-iteration-data-variables/7987/9 "2019-10-03T21:43:15Z")

</div>

Hi Marc,

Do you mean you have files within directories?  
You just need to add the full path to the image.

The `iterationData` is a JSON file with each JSON object as a different iteration.  
So if you have ` [{ "image: file1" }, { "image": "file2"}],` it will run twice with image being the value at each index. To get files under subdirectories just list the path.

Was that your question?
