Search code examples
pythonjsonapijpeg

How to send photo bytes as JPEG image in text/json request using python


I think that I'm working with a bad API design here, according to the documentation I need to send photo bytes as JPEG in the request, my question is: How to send this bytes in a text/json? below is the documentation to sending photos to this API.

Documentation of sending photos to API

Below is my put request in python:

reply = requests.put(url, data=blob, headers=self.headers)

where blob is the binary of the image.


Solution

  • Found the solution, just encode blob to base64 before and then use the json.dumps.

    blob = json.dumps(blob.encode("base64"))
    reply = requests.put(url, json=blob, headers=self.headers)