Incoming Base64 FileStream to Outgoing Binary HTTP Request

Hello,

I’m trying to convert a Base64 encoded filestream encapsulated in a JSON and sent it with an HTTP request as Binary stream to an endpoint. The endpoint needs to receive a binary Filestream and a Content-Type header: application/pdf, together with two headers for authentication. Do I need to set the body content type to RAW/custom? If I do so I get a message “cannot set header accept in the string”. With Multipart/Formdata It processes, but then it breaks on the receiving side, because they want binary, not Multipart/formdata. Any ideas?

{
“name”: “UploadBinaryPDF”,
“nodes”: [
{
“parameters”: {},
“name”: “Start”,
“type”: “n8n-nodes-base.start”,
“typeVersion”: 1,
“position”: [
250,
300
]
},
{
“parameters”: {
“httpMethod”: “POST”,
“path”: “413fc66e-641c-4952-ba17-5374c5077721”,
“options”: {}
},
“name”: “Webhook”,
“type”: “n8n-nodes-base.webhook”,
“typeVersion”: 1,
“position”: [
280,
460
],
“webhookId”: “413fc66e-641c-4952-ba17-5374c5077721”
},
{
“parameters”: {
“requestMethod”: “PUT”,
“url”: “={{$node[“Webhook”].json[“body”][“uploadURL”]}}”,
“jsonParameters”: true,
“options”: {
“bodyContentType”: “multipart-form-data”
},
“sendBinaryData”: true,
“headerParametersJson”: “={\n"authorization”:"{{$node[“Webhook”].json[“headers”][“authorization”]}}",\n"application":"{{$node[“Webhook”].json[“headers”][“application”]}}"\n}"
},
“name”: “HTTP Request”,
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 1,
“position”: [
650,
460
]
},
{
“parameters”: {
“mode”: “jsonToBinary”,
“convertAllData”: false,
“sourceKey”: “body.file”,
“options”: {
“dataIsBase64”: true,
“fileName”: “={{$node[“Webhook”].json[“body”][“fileName”]}}”,
“mimeType”: “={{$node[“Webhook”].json[“body”][“mimeType”]}}”
}
},
“name”: “Move Binary Data”,
“type”: “n8n-nodes-base.moveBinaryData”,
“typeVersion”: 1,
“position”: [
460,
460
]
}
],
“connections”: {
“Webhook”: {
“main”: [
[
{
“node”: “Move Binary Data”,
“type”: “main”,
“index”: 0
}
]
]
},
“Move Binary Data”: {
“main”: [
[
{
“node”: “HTTP Request”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“active”: true,
“settings”: {},
“id”: 18
}

Try it like the image below. Make sure the headers are a JSON with key-value pairs.

Example Workflow:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -390,
        200
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://webhook.site/f7396e19-6552-473c-b8a9-682d2503a4ae",
        "responseFormat": "string",
        "jsonParameters": true,
        "options": {
          "bodyContentType": "raw",
          "bodyContentCustomMimeType": "application/pdf"
        },
        "sendBinaryData": true,
        "headerParametersJson": "={{{ \"value\": 1, \"value2\": 2 }}}"
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        110,
        200
      ]
    },
    {
      "parameters": {
        "url": "https://cdn.pixabay.com/photo/2016/12/18/13/45/download-1915753_1280.png",
        "responseFormat": "file",
        "options": {}
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        -140,
        200
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Cannot create property ‘Content-Type’ on string

…different error now…