8

I know how to post json and I know how to post file in multipart form in Postman. But how can I do both together. For example:

Here is my jason to post:

{
    "title": "Post title yeah",
    "body": "My first post body"

}

So how can I post image.jpg located at /home/me/Desktop along with the the above json?

UPDATE: Note that I want so send file using JSON, so my question is different from this which is about multipart form sending using Postman.

Karlom
  • 13,323
  • 27
  • 72
  • 116
  • Possible duplicate of [Tool for sending multipart/form-data request](https://stackoverflow.com/questions/16015548/tool-for-sending-multipart-form-data-request) – Bob Swager Jul 15 '17 at 19:32
  • @BobSwager Here I want to send file exclusively along with JSON, so multipart form sending is irrelevant to my question. – Karlom Jul 15 '17 at 19:39
  • @Karlom JSON doesn't support binary data, but if you're willing to convert the `Blob` to base64 encoding, which is 4/3 the size (8/3 in UTF-16, which JavaScript defaults to), I can answer that. – Patrick Roberts Jul 15 '17 at 19:41
  • @PatrickRoberts please do answer. I absolutely need to transfer the file through json. – Karlom Jul 15 '17 at 19:42
  • Wait, postman is a web interface? I thought you were using JavaScript or something... if using a web interface, you really should just use multipart/form-data or binary. – Patrick Roberts Jul 15 '17 at 19:45
  • 1
    Right, postman is a chrome extentsion: https://www.getpostman.com/. You still can answer by mentioning why it is not possible and what is the alternative way? (i.e first encode, the use the encodes string at postman?) – Karlom Jul 15 '17 at 19:48
  • @Karlom, did you find a solution? I have similar requirement. I want to send an image through json payload and receive it as a blob. – Maz Feb 19 '18 at 04:59

1 Answers1

5

You can use this online tool to convert your file to a base64 (https://www.browserling.com/tools/file-to-base64), then you can send it as part of the json. I reduced the size of the base64 string for the answer.

{
    "title": "Post title yeah",
    "body": "My first post body",
    "image": "JVBERi0xLjQKJeLjz9MKMiAwIG9iago8PC9MZW5ndGggMjcyNS9GaWx0ZXIvRmxhdGVEZWNvZGU+PnN0cmVhbQpYCb1c247byBF9X8D/0MC+JIFNs5t9IY0gwHicXRjI2GOPvPsQ5EGrocdKRGmiofby9+kmu5t901BFKoLhi8qqc04Xq07zZr/47r8olz84JlmORKV+3dfoZ7R9If8GcxVkeUZLjijNBEOYZhgT+523C/T6hwJVWVVVaPG1w5IID4gxluESLf6BMMuqkkqYImOMoMU9+tPH/X29R9+/+TNa/Bst/oL+vnjx3aeBkJcZqwQilfwwnU/gjFe843u3bOuYjHcLUstjVYlwgfX6cp+NJtgoI5no6RQKKSWMTGQ9HaG4EDzio2o9QshqckkjMklGMsJAbAqjIBKlyHJOO7acvCb8NcnlFzB7g+kbUqbrykUla0kR491CeVZFdcV4vLC8JFlJy477bre5R4v"
}

enter image description here

Fidel Garcia
  • 405
  • 1
  • 6
  • 16