0

I am trying to add my postman scripts to an azure pipeline. To do this I am trying out newman. I use the postman api to get the latest collection as well as the correct environment. Using the uid and an api key i have created. All good so far. However my collection includes some calls that do file uploads. In postman i tested those by simply selecting the body of the call, selecting form-data and choosing a sample file that is located in the default "postman files" folder.

When testing newman on my local machine, i need to copy all the sample files i want to use for uploads into the same folder that i run newman from.

This solution is not quite right for me though as i use the postman api to get the correct collections and the environments. I need to be able to get those files also from an alternative remote location (such as azure blob storage)

I have found some guides that describe how you can just edit the postman collection file to point the "src" to a remote file. However i cannot find any way to do this directly in postman, in such a way that when newman gets the collection file from the api the correct location is already in the correct place.

"request": {
            "method": "POST",
            "header": [],
            "body": {
                "mode": "formdata",
                "formdata": [
                    {
                        "key": "files",
                        "type": "file",
                        "src": "sample.pdf"
                    }
                ]
            },

Above is the extract from the collection file.

Is there a way i can make that change directly in postman?

zawisza
  • 1,039
  • 2
  • 13
  • 25

1 Answers1

0

Postman scripts have access to files in their working directory. We solved this by having a picture in a folder in our git repo, downloading the scripts to that folder, and referring to that file. This is the task we used in the build pipeline:

- task: CopyFiles@2
  inputs:
    SourceFolder: 
    Contents: |
      **/PostmanTests/test-image.jpg
    TargetFolder: '$(Build.ArtifactStagingDirectory)/postman'
    OverWrite: true
    flattenFolders: true

You can then use the postman API to download the files to the artifact folder created above.

One trick here is that we used a "container" file. We replaced the filename with {{file}} (instead of something like example.pdf) and passed the actual name in the environment file. See JSON below:

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

The environment file would then have the name of the file, in this case test-image.jpg.

Reijer
  • 98
  • 1
  • 9