{ "nodes": [ { "id": "save-gmail-attachments-to-google-drive-0", "name": "Trigger - New Email", "type": "n8n-nodes-base.gmailTrigger", "notes": "has:attachment", "position": [ 680, 300 ], "parameters": { "simple": false, "filters": { "q": "has:attachment", "includeDrafts": false, "includeSpamTrash": false, "readStatus": "both" }, "options": { "downloadAttachments": true }, "pollTimes": { "item": [ { "mode": "everyMinute" } ] }, "maxResults": 50 }, "notesInFlow": true, "typeVersion": 1.4 }, { "id": "save-gmail-attachments-to-google-drive-1", "name": "attach binary data outputs", "type": "n8n-nodes-base.code", "position": [ 900, 300 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "const results=[]; for(const [index,item] of $input.all().entries()){const files=Object.values(item.binary??{});if(!files.length)continue;const address=item.json.from?.value?.[0]?.address;if(typeof address!=='string'||!address.trim())throw new Error('Missing sender address');for(const file of files){const original=file.fileName||'attachment';const dot=original.lastIndexOf('.');const fileName=dot>0?original.slice(0,dot)+'-'+address+original.slice(dot):original+'-'+address;results.push({json:{fileName},binary:{data:file},pairedItem:{item:index}});}} return results;" }, "typeVersion": 2 }, { "id": "save-gmail-attachments-to-google-drive-2", "name": "upload files to google drive", "type": "n8n-nodes-base.googleDrive", "position": [ 1140, 300 ], "parameters": { "name": "={{ $json.fileName }}", "driveId": { "__rl": true, "mode": "list", "value": "My Drive", "cachedResultUrl": "https://drive.google.com/drive/my-drive", "cachedResultName": "My Drive" }, "options": {}, "folderId": { "__rl": true, "mode": "id", "value": "YOUR_DRIVE_FOLDER_ID" } }, "typeVersion": 3 } ], "pinData": {}, "connections": { "Trigger - New Email": { "main": [ [ { "node": "attach binary data outputs", "type": "main", "index": 0 } ] ] }, "attach binary data outputs": { "main": [ [ { "node": "upload files to google drive", "type": "main", "index": 0 } ] ] } }, "name": "Save Gmail Attachments to Google Drive", "active": false }