How to use the form-data in http request node

Hi, I’m new to using n8n and have been stuck for the last 2 days trying to figure this out.

I want to upload a youtube video with the http request node instead of the specific youtube-node. But I’m having problems since I have to both include binary data in the body as well as specify a lot of setting with JSON also in the body.

So after doing a lot of research and chatting with AI’s, it looks like I have to use the form data option. However, I’m missing some tutorials/examples on how fill out the JSON and binary data.

If I ask AI’s they say I have to prepare the data in a previous code node with something like "const FormData = require(‘form-data’);…]

However, I can’t find examples of this either and I get errors from the code that can’t find form-data.

So my question is:

  1. what is the general way of handling my issue with having both binary and json text I need to put in the body of a http request node?
  2. how do I install the needed dependency (form-data in this case)?

thanks!

Information on your n8n setup

  • n8n version: 1.84.1
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): note sure what this means?
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: macOS

The general way is to fork from your node that has the binary into the node where you assemble JSON, and also directly to a merge with “combine” by “position”. Then add a link from the JSON node to the other input of the merge.

Here is an example from another post.

There’s another, more recent reference to a similar scenario here.

Maybe I was answering the wrong question. Getting both JSON data and and binary data into the same place in the workflow is usually the issue. So, I’m hoping this adds some context to your original question.

To set up the actual HTTP Request node for a YT video upload, I assume you are following this API documentation.

I don’t have an API client set up with Youtube APIs active, so I’ll have to do that and experiment more later, but already I have found it challenging to figure out what value to supply for the multipart “part” that isn’t the video content binary data.

Have you already tried setting up the HTTP Request node to use both a binary, and “Form Data”, like this?

Update: Got the form-data library part of it solved. That just requires an npm install on top of n8n in the container image.

  1. Create a custom Dockerfile and store it where docker-compose.yml is.
    ARG tag=latest
    FROM n8nio/n8n:$tag
    USER root
    RUN npm install -g form-data
    USER node
    
  2. Modify docker-compose.yml to run that and add the library to what n8n can use.
    a. Add after image: n8n:1.77.1 (or whatever version you’re using)
        build:
            context: .
            dockerfile: Dockerfile
    
    b. Add in the environment: section
        - NODE_FUNCTION_ALLOW_EXTERNAL=form-data
    
  3. docker compose up --no-start && docker compose start
  4. Test to be sure the form-data library is available.
2 Likes

I couldn’t get this to work. However, with your form-data library solution, I think I have what it takes to solve the problem, ty!

(ps. n8n should make it easier to install libraries :sweat_smile: )

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.