1

Scenario

I have a POST request API which accepts Image or File. As shown below:

enter image description here

I can select an image from the Request body as a form-data but, here I can select one image at a time.

But I want to upload multiple images or files as a form-data variable like {{image}} or {{file}} while doing Postman-Collection Runner. As we know, we can only upload text/JSON/CSV file as iteration data in Postman Runner.

Questions: Is there any way from which we can send multiple images or files as Iteration data in Postman Runner or in Newman?

or

Can I have a Postman test script that will upload multiple images or files in Postman Runner?

Or else

Help me in how to upload multiple images using Newman.

Can anyone please help me with this?

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37
chandan prasad
  • 111
  • 1
  • 10
  • needs detail or clarity. – Babak Asadzadeh Oct 19 '20 at 12:16
  • Does this answer your question? [In Postman, how to POST binary file use collection runner](https://stackoverflow.com/questions/45799280/in-postman-how-to-post-binary-file-use-collection-runner) – Christian Baumann Oct 19 '20 at 12:42
  • @Babak It's pretty, clear, but not possible: See https://stackoverflow.com/questions/45799280/in-postman-how-to-post-binary-file-use-collection-runner or https://blog.postman.com/run-collections-with-file-uploads-using-newman/ – Christian Baumann Oct 19 '20 at 12:43
  • @ChristianBaumann Thanks for this reference: https://blog.postman.com/run-collections-with-file-uploads-using-newman/ I got pretty good clarification on this. But Can you please tell me, Is there any way to send multiple files in the `POST` request asynchronously? but not at the same time as it's mentioned in the above link. – chandan prasad Oct 19 '20 at 15:18
  • 1
    [Moorthi Rajendiran](https://stackoverflow.com/users/12267300) posted an [Answer](https://stackoverflow.com/a/67090829) saying "I referred the below link and updated the setting. Now it is working for me. [https://support.postman.com/hc/en-us/articles/360023574653-Storage-of-file-Working-Directory-in-reference-for-collections](https://support.postman.com/hc/en-us/articles/360023574653-Storage-of-file-Working-Directory-in-reference-for-collections)" – Scratte Apr 19 '21 at 07:39
  • Thanks, @MoorthiRajendiran. It really helped me a lot. Thank you so much. – chandan prasad Jun 07 '21 at 07:15

2 Answers2

0

What you can possibly do is , create those many test cases in your iteration data file. for example if you want to upload 10 images so you can create 10 testcases in your test data file and run it as a part of collection runner

Deepak Tiwari
  • 131
  • 1
  • 5
  • Well, Thanks for this. But, I know this, and I did like this only. AND, it's time-consuming and it won't look good in `collection` if you have too many files. – chandan prasad Nov 04 '20 at 10:54
0

I had the same issue and solve it without newman.

I exported my collection in json and set "src": "{{value}}" in the body of exported .json file:

"body": {
                    "mode": "formdata",
                    "formdata": [
                        {
                            "key": "file",
                            "type": "file",
                            "src": "{{value}}"
                        }
                    ]
                }

After that I added new json file with different files for value:

[{
  "path": "post",
  "value": "1.png"
}, {
  "path": "post",
  "value": "2.png"
}, {
  "path": "post",
  "value": "3.png"
}, {
  "path": "post",
  "value": "4.png"
}]

Be sure that these files exists in working directory of postman (it can be set in settings)

After that I imported these collection back into postman. The form-data of the request is: enter image description here

When we run the collection we choose in data the json file with values. enter image description here

The result was that my request executes 4 times and every time it uploads different file.