Basic starting question: how to download a list of files, starting from URL?

Describe the issue/error/question

Hi,
these are my first steps using this great tool. I have created my workflow to dowload a list of pdfs from a list of webpages.

Now I have a list of binaries. How to save each in my PC (I’m using n8n desktop).

What is the error message (if any)?

Please share the workflow

(Select the nodes and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow respectively)

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        100,
        240
      ]
    },
    {
      "parameters": {
        "url": "https://www.regione.sicilia.it/la-regione-informa?title=bollettino&start_date=&end_date=",
        "allowUnauthorizedCerts": true,
        "responseFormat": "string",
        "options": {
          "fullResponse": true
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        300,
        390
      ]
    },
    {
      "parameters": {
        "extractionValues": {
          "values": [
            {
              "key": "item",
              "cssSelector": ".res-card-message__title",
              "returnValue": "html",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "name": "HTML Extract",
      "type": "n8n-nodes-base.htmlExtract",
      "typeVersion": 1,
      "position": [
        300,
        110
      ]
    },
    {
      "parameters": {
        "dataPropertyName": "item",
        "extractionValues": {
          "values": [
            {
              "key": "title",
              "cssSelector": "a"
            },
            {
              "key": "url",
              "cssSelector": "a",
              "returnValue": "attribute",
              "attribute": "href"
            }
          ]
        },
        "options": {}
      },
      "name": "HTML Extract1",
      "type": "n8n-nodes-base.htmlExtract",
      "typeVersion": 1,
      "position": [
        540,
        110
      ]
    },
    {
      "parameters": {
        "url": "={{$node[\"HTML Extract1\"].json[\"url\"]}}",
        "allowUnauthorizedCerts": true,
        "responseFormat": "string",
        "options": {}
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        520,
        400
      ]
    },
    {
      "parameters": {
        "extractionValues": {
          "values": [
            {
              "key": "title",
              "cssSelector": ".h3"
            },
            {
              "key": "href",
              "cssSelector": "a.read-more",
              "returnValue": "=attribute",
              "attribute": "=href"
            }
          ]
        },
        "options": {
          "trimValues": true
        }
      },
      "name": "HTML Extract2",
      "type": "n8n-nodes-base.htmlExtract",
      "typeVersion": 1,
      "position": [
        700,
        360
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [],
          "string": [
            {
              "value1": "={{$node[\"HTML Extract2\"].json[\"href\"]}}",
              "operation": "isEmpty"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        300,
        660
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "URL",
              "value": "=https://www.regione.sicilia.it{{$json[\"href\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        510,
        680
      ]
    },
    {
      "parameters": {
        "url": "={{$json[\"URL\"]}}",
        "allowUnauthorizedCerts": true,
        "responseFormat": "file",
        "options": {}
      },
      "name": "HTTP Request2",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        700,
        640
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "HTML Extract",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Extract": {
      "main": [
        [
          {
            "node": "HTML Extract1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Extract1": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "HTML Extract2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Extract2": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        null,
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "HTTP Request2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Share the output returned by the last node

Information on your n8n setup

I’m using n8n desktop.

Thank you

Welcome to the community @aborruso

Use the Write Binary File node.

Example Workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "fileName": "/Users/ricardoe105/image.jpg"
      },
      "name": "Write Binary File",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        750,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://i.guim.co.uk/img/media/684c9d087dab923db1ce4057903f03293b07deac/205_132_1915_1150/master/1915.jpg?width=1200&height=1200&quality=85&auto=format&fit=crop&s=14a95b5026c1567b823629ba35c40aa0",
        "responseFormat": "file",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        480,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Write Binary File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

It works, thank you :pray:

How to set the local folder, where to save the files?

If I put C:\Users\aborr\Documents\test\{{$binary.data.fileName}} I have no result.

If I set only {{$binary.data.fileName}} I have the files in C:\Users\aborr\AppData\Local\Programs\n8n.

Weird. It works just fine for me. I’m not a Windows user, though.

@MutedJam can you please test it out?

1 Like

I can actually reproduce this. The expression editor itself works fine here:
image

However, when actually running this, the behavior seems very unexpected to Windows-me:

The file gets stored into as C:\Users\Tom\Documents{{$binary.data.fileName}} in this example:

It worked when replacing the last backslash with a forward slash though (C:\Users\Tom\Documents/{{$binary.data.fileName}}:

Could you try if the single forward slash is working for you as well @aborruso?

1 Like

it works, thank you very much.

Do I must open a new issue for this bug? If yes, what’s the right place to do it?

1 Like

Glad to hear this is working for you, thanks a lot for confirming!

I’ve already raised this as a bug internally so you won’t have to do anything here (apart from using that forward slash for now, unfortunately).

2 Likes