7
votes

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.

1
@BobSwager Here I want to send file exclusively along with JSON, so multipart form sending is irrelevant to my question.Karlom
@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
@PatrickRoberts please do answer. I absolutely need to transfer the file through json.Karlom
Right, postman is a chrome extentsion: 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

1 Answers

3
votes

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