Changing file name from binary

I’m using HTTP Request to get the pdf from a Gogle Docs, but the file name is shown as Export, is it possible to replace this name with the actual file name?

You can use the function node with the following code to do so. It might be worth adding it as an option to the HTTP node, though.

items[0].binary.data.fileName = 'newname.pdf'
return items;
Example workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://s2.q4cdn.com/498544986/files/doc_downloads/test.pdf",
        "responseFormat": "file",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "items[0].binary.data.fileName = 'newname.pdf'\nreturn items;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        740,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
2 Likes

Perfect @RicardoE105

Thank you very much!

As I need to use the name of the file that is in Drive, it looks like this :+1::wink:

items[0].binary.data.fileName = $node["Google Drive Trigger"].json["name"]+'.pdf' 
return items;
1 Like

Hi,

I’m using the code to change the file name to the original gdocs name, but only the first file is changed. The rest is still shown as “Export”. Any help on this?

Hi @Azril

I solved this problem by adding an Items Lists (configured as pictured) after the IF and including a Loop

Capturar1

I took advantage of your appointment to adjust my flow to avoid future problems, which would certainly occur.

1 Like

Yes, now its working perfectly.
Many thanks for your workflow!!

2 Likes