How to set POST request Binary body for Postman Iterations?

How to process multiple files (from HTTP directory or file system) by Postman + Data File with URLs?

I did:

  1. in Pre-Request, Download and save file into the env variable.
  2. POST Request is in the Raw mode, body is set from env variable.

That not works for binary data - data corrupted
after js.buffer.toString('binary') (Maybe UTF-8 encoded?)

Looking for other solutions.

request body from collection.json:

"body": {
    "mode": "raw",
    "raw": "{{data-binary}}" }

pre-request script:
get url from data file (iterationData) and download file by pm.sendRequest

pm.sendRequest(
    pm.iterationData.get('fileUrl'),
    function (err, res) {
        var buffer = res.stream;
        pm.environment.set('data-binary', 
            buffer.toString('binary'));
    }
);

ps.

Hello,

Any news about this use case ? Since the raw body type seems to change the binary content, and the file body type only accept an effective file on the machine we can not provide environment base64 representation of the wanted body.

Since postman does not allow the pre-script to write a temporary file, i have no more ideas how to use postman to send binary content in an automation process.

BR

Hi, did you find a solution?

Somebody found a solution to this?

I was happy to see that there is since Postman v8.3.0 finally a easy way to update the request body from pre-script, but looks like this is not working correctly for binary data despite the body mode is set to β€œraw”.

So how can we update the request body before sending via pre-script to (AES-encrypted) binary data?
It should be sent as β€œapplication/octet-stream” content-type, so no base64 encoding needed.