Store and access external file from binary

Hi
I am using Postman ‘POST’ request to send a file which is uploaded to the request body from binary - see screenshot below.
Now I need a way to store the file so that I can access it and compare its content to the content in a response to a respective call to ‘GET’, for test purposes.
Is there a way to achieve that?
image

Hey @davidronen :wave:

Welcome to the Postman Community! :postman:

You will not be able to access and read content from a file, in your local file system using Postman.

Files can be attached to requests for certain scenarios but you wouldn’t be about to directly read the contents of any file and compare that with a response via the UI.

Hi Danny,
Thanks a lot for your response.
I was under the impression that it will be possible to do something like:

  1. Upload the file from binary (as shown in my previous post), then
  2. Get the content , e.g. as echo the content to a String, then
  3. Take the String and do something like:
var body_str = getFileContentInSomeWay();
var requestAsJson = JSON.parse(body_str);
pm.environment.set('request_body', body_str);
pm.collectionVariables.set('var_name',requestAsJson);

Am I way off?

You could do it that way using some kind of echo service but it would be a workaround and I’m not 100% sure that it would be a 1:1 comparison. :thinking:

You’d also be introducing an extra call to that service, only to echo the content. Failing that, you could probably be this in a script using your favorite language.

It’s worth experimenting for sure :smiley:

OK, so no “ready (and easy) to use” function/library for that… (?)
Wired.
Thanks :slight_smile:

Postman has never had direct access to read the contents of the files from your file directory, using the scripting environment.

There are certain places in the platform that allow you to use specific data files but that’s about it.

The testcase scenario is as follows:

  1. ‘POST’ some data (I chose to do that by uploading a ready file as binary in the ‘POST’ request body).
  2. The application does some computations on the data and stores it.
  3. Verify that the stored data is correct after the computations. I thought of using a ‘GET’ call and comparing the ‘POST’ values with the ‘GET’ values.

I have access to the posted data if I create the payload within a pre-request script. However this is tedious, especially since the requested data is already automatically generated into a file, which I then upload into the ‘POST’ request body.
I hoped that Postman will have a way to read the payload into a variable, so that comparison is easily done within a post-request ( pm.test() ) in the ‘GET’ call.
Apparently no such way…(?)