Image content retrieved from SourceGraph GraphQL API doesn't render when base64 encoded

I need to retrieve image content from GitHub using SourceGraph GraphQL API, base64 encode it and add it to an html and render it. When I base64 encode the image string and add it to html, image is not getting rendered. I used UTF-8 encoding. I tried with utf-16 or ascii encoding also but that didnt help.
When i download the same image , I am able to base64 encode the image and render it just fine.
Below is the code used-

GraphQL Query:

 query {
  repository(name: "RepoName") {
    defaultBranch {
      target {
        commit {
          blob(path: "Image file path") {

Snippet of the content returned ->"�PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0004u\u0000\u0000\u0002�\b\u0006\u0000\u0000\u0000B��\u000e\u0000\u0000\u0000\u0001sRGB\u0000��\u001c�\u0000\u0000\u0000\u0004gAMA\u0000\u0000��\u000b�a\u0005\u0000

Python code -

response =
        "query": body,
        "variables": {
            "query": variables_query

if response.status_code == 200:
    result = response.json()
    resultSet = result["data"]["search"]["results"]["results"]
    file_content_string = resultSet[0]["file"]["content"]
    file_content_bytes = file_content_string.encode("utf-8")
    file_content_string = base64.b64encode(file_content_bytes)

Hey @priyadun! I hope you don’t mind that I formatted the code examples for better readability. I’m going to need to ask someone what is happening here. Please stand by :slight_smile:

@priyadun update from engineering:

We utf-8 escape all files so they can be displayed as text.

I’d recommend using the raw endpoint instead of GraphQL. E.g.