Save invoice attachments from Gmail to Drive

Invoices that arrive by email are filed into a Drive folder automatically.

Easy Saves ~3 hours/month Finance & AdminBy Flowngn team

Works with n8n · Make · Zapier

How it works

Trigger: Gmail — new email matching "invoice has:attachment"
  1. Watch Gmail for emails with "invoice" and an attachment.
  2. Download the attachments.
  3. Upload them to a Drive folder named by month, e.g. "Invoices/2026-09".

Diagram

GInvoice emailGmail Trigger{ }Split attachmentsCodeGUpload to DriveGoogle Drive
Trigger App Code

Code

JavaScript used in the Code step — already included in the template below.

Split attachments · Code node
// Splits every attachment into its own item and gives it a sortable file name:
// 2026-09-26-supplier.com-invoice.pdf
const out = [];

for (const item of $input.all()) {
  const date = new Date(item.json.date).toISOString().slice(0, 10);
  const sender = item.json.from?.value?.[0]?.address || "unknown@unknown";
  const domain = sender.split("@")[1];

  for (const file of Object.values(item.binary || {})) {
    out.push({
      json: { fileName: `${date}-${domain}-${file.fileName}` },
      binary: { data: file },
    });
  }
}

return out;

Build it

Pick your tool — same automation, step by step.

Copy and paste straight into an n8n canvas (Ctrl+V), or download and use Import from File. Then connect your own credentials and replace every YOUR_… placeholder.

Workflow JSON
Show code (116 lines)
{
  "name": "Save invoice attachments from Gmail to Drive (Flowngn)",
  "nodes": [
    {
      "parameters": {
        "content": "## Save invoice attachments from Gmail to Drive\nInvoices that arrive by email are filed into a Drive folder automatically.\n\n**Setup**\n1. Open each node and connect your own credentials.\n2. Replace every YOUR_… placeholder.\n3. Test once, then activate.\n\nFree template from Flowngn",
        "height": 260,
        "width": 340
      },
      "id": "35c47c31-a6eb-42db-a482-bc5e476f5441",
      "name": "Setup notes",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -420,
        -60
      ]
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyHour"
            }
          ]
        },
        "simple": false,
        "filters": {
          "q": "invoice has:attachment"
        },
        "options": {
          "downloadAttachments": true
        }
      },
      "id": "35c47c31-a6eb-42db-a482-bc5e476f5441",
      "name": "Invoice email",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Splits every attachment into its own item and gives it a sortable file name:\n// 2026-09-26-supplier.com-invoice.pdf\nconst out = [];\n\nfor (const item of $input.all()) {\n  const date = new Date(item.json.date).toISOString().slice(0, 10);\n  const sender = item.json.from?.value?.[0]?.address || \"unknown@unknown\";\n  const domain = sender.split(\"@\")[1];\n\n  for (const file of Object.values(item.binary || {})) {\n    out.push({\n      json: { fileName: `${date}-${domain}-${file.fileName}` },\n      binary: { data: file },\n    });\n  }\n}\n\nreturn out;"
      },
      "id": "35c47c31-a6eb-42db-a482-bc5e476f5441",
      "name": "Split attachments",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        300,
        0
      ]
    },
    {
      "parameters": {
        "name": "={{ $json.fileName }}",
        "driveId": {
          "__rl": true,
          "value": "My Drive",
          "mode": "list"
        },
        "folderId": {
          "__rl": true,
          "value": "YOUR_INVOICES_FOLDER_ID",
          "mode": "id"
        },
        "inputDataFieldName": "data",
        "options": {}
      },
      "id": "35c47c31-a6eb-42db-a482-bc5e476f5441",
      "name": "Upload to Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        600,
        0
      ]
    }
  ],
  "connections": {
    "Invoice email": {
      "main": [
        [
          {
            "node": "Split attachments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split attachments": {
      "main": [
        [
          {
            "node": "Upload to Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}

Open in the playground to edit →

Tips

  • Rename files as date-sender-originalname so they sort nicely.

Related flows