Json to picture (base64)

Hi

We have now managed to convert a picture to base 64.

Now we are trying to convert it back from JSON to picture but can’t manage. I have attached the workflow below:

{
  "nodes": [
    {
      "parameters": {
        "url": "=https://uknow.uky.edu/sites/default/files/styles/uknow_story_image/public/GettyImages-1160947136%20%281%29.jpg",
        "responseFormat": "file",
        "options": {}
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        690,
        330
      ]
    },
    {
      "parameters": {
        "setAllData": false,
        "options": {
          "encoding": "utf8",
          "keepAsBase64": true
        }
      },
      "name": "pictureToJson",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        1060,
        330
      ]
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "options": {}
      },
      "name": "jsonToPicture",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        1260,
        330
      ]
    }
  ],
  "connections": {
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "pictureToJson",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "pictureToJson": {
      "main": [
        [
          {
            "node": "jsonToPicture",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hi @Mattias_Larsson, how are you doing?

This workflow should help you out:

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "\nreturn [\n  {\n  json: {\n    \n  },\n  binary: {\n    data: {\n      data: $node['pictureToJson'].json.data,\n      mimeType: \"image/jpeg\",\n      fileExtension: 'jpg',\n      fileName: \"image.jpg\"\n    }\n  }\n  }\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        850,
        450
      ]
    },
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        450
      ]
    },
    {
      "parameters": {
        "url": "=https://uknow.uky.edu/sites/default/files/styles/uknow_story_image/public/GettyImages-1160947136%20%281%29.jpg",
        "responseFormat": "file",
        "options": {}
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        450,
        450
      ]
    },
    {
      "parameters": {
        "setAllData": false,
        "options": {
          "keepAsBase64": true
        }
      },
      "name": "pictureToJson",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        650,
        450
      ]
    },
    {
      "parameters": {
        "functionCode": "\nreturn [\n  {\n  json: {\n    \n  },\n  binary: {\n    data: {\n      data: $node['pictureToJson'].json.data,\n      mimeType: \"image/jpeg\",\n      fileExtension: 'jpg',\n      fileName: \"image.jpg\"\n    }\n  }\n  }\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        850,
        450
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "pictureToJson",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "pictureToJson": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hope that helps, have fun! :slight_smile:

1 Like