imagepostmanbinary-data

Question about what an Image Is Turned into when You Use Postman Binary Body


When you are sending an image file with the body type of binary in postman what how is the image being encoded when it is sent or what is the image being turned into when it is sent? Is it being sent in a byte array, byte string, binary string, or something else?


Solution

  • It is sent as raw bytes. Just the data as-is. No encoding. It is the same as raw but you can specify a file instead of having a textbox (as the textbox would already limit would you could put into it).

    Request in Postman:

    enter image description here

    Original file gif, for comparison (screenshot from HxD):

    enter image description here

    Data sent (screenshot from SmartSniff):

    enter image description here

    Text representation (screenshot from SmartSniff as well):

    enter image description here

    You can see that after the headers, the original GIF file is appended as-is (starting at offset 0x116 in the hex dump).


    Additional Information

    Addressing your comment:

    Is it like a byte string?

    All network communication is a stream of bits grouped into octets (bytes). I don't know what you mean by the term "byte string", but the data here is just transmitted without modification, every bit stays the same. (On a protocol (HTTP) level, that is. Of course there is all the remaining network stack below that which splits your data into packets and such.)

    The Python bytes literal b'\x41\x42\x43' and the Python string 'ABC' and the bytes 41, 42 and 43 (when viewed in hexadecimal notation) in succession all represent the same thing in some way. At the end, you get a handful of zeroes and ones and those are stored/sent/whatever. (Yes it gets complicated with Non-ASCII literals but still the b'\xAB' notation is just a way to represent bytes with given values.)

    would the image being sent be like b'...'?

    That's sort of the wrong question, it doesn't have any meaningful answer.

    Example: The letter A is normally represented by a byte with value 41 (hex - 65 in decimal), or 01000001 in binary. Those 8 bits are the information that is sent. If you write b'\x41' in Python you get the same thing - one byte with the bits 01000001. So it doesn't make sense to ask if the A is sent as b'\x41' or not, unless you mean the actual characters b'\x41' as you would type them into your code file - in that case no, because those would be 7 bytes and it doesn't make sense to do that if we could just send one byte (consisting of the value representing A) instead.

    Say if I was to send the image using an http client what data format would I put the image in to send it to an api that is like sending the image with a binary body in postman?

    In Python you have several ways to represent raw binary data, and when sending the contents of a file you can just read the file with the binary mode and pass the data to the HTTP request:

    requests.post(
      url='http://httpbin.org/post',
      data=open('./image.gif', 'rb').read(),
      headers={'Content-Type': 'application/octet-stream'}
    )
    

    In node.js, you could store such data in a Buffer object. And in C#, you would use a byte array (Byte[]). Most languages have some sort of way to represent a chain of bytes like that with no additional meaning imposed on them yet.