Skip to content

Instantly share code, notes, and snippets.

@lintangsutawika
Created October 20, 2018 17:10
Show Gist options
  • Save lintangsutawika/9da34ab1ab66337594ea3b647d3a8194 to your computer and use it in GitHub Desktop.
Save lintangsutawika/9da34ab1ab66337594ea3b647d3a8194 to your computer and use it in GitHub Desktop.
import json
import base64
IMAGE_FILE = "example.png"
with open(IMAGE_FILE, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
base64_string = encoded_string.decode('utf-8')
json_data = dumps({'image': base64_string}, indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment