Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending Binary Data with Postman and Newman

I am trying to create a collection that will upload images and be able to run it in multiple iterations and want to use newman to run it.

For our API it only supports uploading images through using binary data.

https://www.getpostman.com/docs/requests - Postman does not support saving the files for both form-data and binary.

https://www.getpostman.com/docs/run_file_post_requests - They show how you can upload images with Newman using form-data, but not for binary.

Is it possible to use newman with binary image upload?

like image 532
Tyler S Avatar asked Nov 08 '22 08:11

Tyler S


2 Answers

here is what you need in your request. I had to modify the src from the saved collection

{
            "name": "Room Document", 
            "request": {
              "url": "{{url}}/api/v1/folders/321/documents",
              "method": "POST",
              "header": [
                {
                  "key": "Accept",
                  "value": "application/json",
                  "description": ""
                },
                {
                  "key": "Authorization",
                  "value": "3242349-324432-23423423-23424",
                  "description": ""
                }
              ],
              "body": {
                "mode": "formdata",
                "formdata": [
                  {
                    "key": "file",
                    "type": "file",
                    "src": "blank.pdf"
                  }
                ]
              },
              "description": " "
            },
            "response": []
          },
like image 54
eiu165 Avatar answered Dec 08 '22 00:12

eiu165


I used it like this which worked with the binary:

"body": {
    "mode": "file",
    "file": {
        "src": "path/to/your/file.jpg"
    }
}

That way you dont have to set the KEY, Type and so on. But you need to set it within the Header as

Content-Disposition: attachment; filename="file.jpg"

and in our case with

Content-Type: application/octet-stream
like image 26
ToAst Avatar answered Dec 08 '22 01:12

ToAst