Download multiple files with http-request node

Describe the problem/error/question

Hello!
I’m new to n8n and I’m trying out a very simple workflow: URLs to files from a webhook should be downloaded and saved on my Nextcloud. I also use the “Split Out Items” node at the beginning to only extract certain URLs from the json file of the webhook.
But I have 2 problems:

  1. How do I define the “HTTP Request” node to download all URLs from the output of the “Split Out Items” node?

  2. How do I define the Nextcloud node so that it saves the downloaded files under their original name?

Please share your workflow

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Ok, I missed some information about the system, hope this helps:

  • n8n version: 1.18.2
  • Database (default: SQLite): Postgress 11
  • n8n EXECUTIONS_PROCESS setting (default: own, main): ?
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: Debian 11

OK, I will answer to myself, i figured it out:
/Filepath/{{ $('HTTP Request').item.binary.data.fileName }}

But my initial problem remains, how to download multiple files??

The webhook-json-file looks like this:

[
  {
    "headers": {
      "host": "n8n.testing.xyz",
      "content-length": "280",
      "accept": "application/json",
      "accept-encoding": "deflate, gzip, br",
      "content-type": "application/json",
      "x-forwarded-for": "X.X.X.X",
      "x-forwarded-host": "n8n.testing.xyz",
      "x-forwarded-port": "443",
      "x-forwarded-proto": "https",
      "x-forwarded-server": "traefik",
      "x-real-ip": "X.X.X.X"
    },
    "params": {},
    "query": {},
    "body": {
      "Upload 1": "https://testing.xyz/1.jpg",
      "Upload 2": "https://testing.xyz/2.jpg",
      "Upload 3": "https://testing.xyz/3.jpg",
      "Upload 4": "https://testing.xyz/4.jpg"
    }
  }
]

I want to download the files from the url “Upload 1” to “Upload 4”. How to define Http Request Node to loop?

OK, I’m answering myself again.
I figured out that the “Http Request”-Node works correct with internal looping when the output from the previous node looks like this (I changed the output manually, it shows up as 4 items):

[
  {
    "url": "https://testing.xyz/1.jpg"
  },
  {
    "url": "https://testing.xyz/2.jpg"
  },
  {
    "url": "https://testing.xyz/3.jpg"
  },
  {
    "url": "https://testing.xyz/4.jpg"
  }
]

Then a simple

{{ $json.url }}

in the “HTTP Request” URL-Field and it works as it should.

But, how can n8n convert the following output from the “Split out items”-node (1 item) to look like above (4 items)? This is the JSON that needs to be converted:

[
  {
    "body['Upload 1']": "https://testing.xyz/1.jpg",
    "body['Upload 2']": "https://testing.xyz/2.jpg",
    "body['Upload 3']": "https://testing.xyz/3.jpg",
    "body['Upload 4']": "https://testing.xyz/4.jpg"
  }
]

Would be nice if someone has a solution!

And once again I have to answer myself. To perform the array conversion mentioned above, I had to write some code, the “Edit Field” node was unable to do this.

And this is the final working workflow:

2 Likes

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