How to create an html file and http post?

Hey guys,
I am trying to create an html file, and then post the file via http, I played around with the binary file creation but can’t seem to get it. Any help would be welcomed, thanks!

{
  "nodes": [
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://somesiteupload.com/api",
        "options": {
          "bodyContentType": "raw",
          "bodyContentCustomMimeType": "text/html"
        },
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "index.html",
              "value": "={{$node[\"Set\"].json[\"data\"]}}"
            },
            {
              "name": "anotherparam",
              "value": "keyhere"
            },
            {
              "name": "anotherparamhere",
              "value": "keyhere"
            }
          ]
        },
        "headerParametersUi": {
          "parameter": []
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        740,
        260
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "file",
              "value": "=<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Test for index.html</title>\n</head>\n<body>\n \n</body>\n</html>"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        440,
        260
      ]
    }
  ],
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

It would be more something like this:

{
  "nodes": [
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://somesiteupload.com/api",
        "jsonParameters": true,
        "options": {
          "bodyContentType": "raw",
          "bodyContentCustomMimeType": "text/html"
        },
        "sendBinaryData": true
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        920,
        340
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "file",
              "value": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Test for index.html</title>\n</head>\n<body>\n \n</body>\n</html>"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        520,
        340
      ]
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "convertAllData": false,
        "sourceKey": "file",
        "options": {
          "mimeType": "\ttext/html"
        }
      },
      "name": "Move Binary Data",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        700,
        340
      ]
    }
  ],
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "Move Binary Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

But it is currently sadly not possible with the HTTP Request Node to send binary + other body data.

Thanks @jan

Perhaps I might be able to curl via execute command with the binary file and other params?

You can also do it via the Function-Node and importing axios/request.

1 Like