Multi-branch workflow in n8n

Describe the problem/error/question

Hi everyone. I’m using n8n building a workflow that reads a csv, extract some prompts and then use gemini (edit image) node for modify a given image with the prompt extract before.

Unfortunately gemini recive only on arguments per time, so the image remains the same because no prompt is pass to gemini or the workflow raise an error because gemini miss the image to modify.

I try to make this workflow more complex, so i realize this

with code node js “return [
{ json: { branch: ‘csv’} },
{ json: { branch: ‘image’} }
];“ and switch on the branch key, but onfortunately the download image node lost is propertis, no more “name“ or “id“ fields are present.

Have you got some tips?

first workflow

{
“nodes”: [
{
“parameters”: {
“fieldToSplitOut”: “prompt”,
“include”: “selectedOtherFields”,
“fieldsToInclude”: “shotNumber”,
“options”: {}
},
“type”: “n8n-nodes-base.splitOut”,
“typeVersion”: 1,
“position”: [
960,
-112
],
“id”: “ca1c1ba5-9cac-432c-8094-d4578216d47d”,
“name”: “Split Out”
},
{
“parameters”: {
“inputDataFieldName”: “fileToWrite”,
“name”: “={{ $json.shotNumber }}”,
“driveId”: {
“__rl”: true,
“value”: “https://drive.google.com/drive/folders/1Qo1PoAcYxW4sD7RxnZtxPUrIidahChWe”,
“mode”: “url”
},
“folderId”: {
“__rl”: true,
“value”: “https://drive.google.com/drive/folders/1Qo1PoAcYxW4sD7RxnZtxPUrIidahChWe”,
“mode”: “url”
},
“options”: {}
},
“type”: “n8n-nodes-base.googleDrive”,
“typeVersion”: 3,
“position”: [
1552,
80
],
“id”: “38c72991-dbd8-439f-a5f5-23ef2e03386a”,
“name”: “Upload file”,
“credentials”: {
}
},
{
“parameters”: {
“options”: {}
},
“type”: “n8n-nodes-base.extractFromFile”,
“typeVersion”: 1,
“position”: [
784,
-112
],
“id”: “c84eceef-51e7-4ca8-9f19-75ad6d793c37”,
“name”: “Extract from CSV file”
},
{
“parameters”: {
“resource”: “image”,
“operation”: “edit”,
“prompt”: “=genera un fotogramma a partire dall’immagine in input dal seguente prompt: {{$json.prompt}}”,
“images”: {
“values”: [
{
“binaryPropertyName”: “=data{{ $json.id }}”
}
]
},
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.googleGemini”,
“typeVersion”: 1,
“position”: [
1152,
80
],
“id”: “0988a417-7088-4f38-8417-0b1d502c3510”,
“name”: “Gemini nano banana 2”,
“credentials”: {
}
},
{
“parameters”: {
“jsCode”: “// Function node → Output: keep as default\nfor (let i = 0; i < items.length; i++) {\n const item = items[i];\n if (!item.binary) continue;\n\n // cerca la chiave source: se esiste item.json.fileName usa quella, altrimenti usa la prima chiave binaria trovata\n const fileName = item.json && item.json.fileName;\n let sourceKey = null;\n if (fileName && item.binary[fileName]) {\n sourceKey = fileName;\n } else {\n const keys = Object.keys(item.binary);\n if (keys.length) sourceKey = keys[0]; // primo campo binario disponibile\n }\n\n if (sourceKey) {\n // copia sotto un nome stabile\n item.binary[‘fileToWrite’] = item.binary[sourceKey];\n // opzionale: elimina il vecchio key se vuoi\n delete item.binary[sourceKey];\n }\n}\n\nreturn items;\n”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
1328,
80
],
“id”: “d7603349-7715-4dfe-a3ca-5172fc11a835”,
“name”: “Code in JavaScript1”
},
{
“parameters”: {
“operation”: “download”,
“fileId”: {
“__rl”: true,
“value”: “https://drive.google.com/file/d/1W5irR95gFudPwf1ZbBxRv_wHzXaAdemE/view?usp=drive_link”,
“mode”: “url”
},
“options”: {}
},
“type”: “n8n-nodes-base.googleDrive”,
“typeVersion”: 3,
“position”: [
640,
-112
],
“id”: “5074d185-923d-4114-8510-fac23f7c1b41”,
“name”: “Download CSV”,
“credentials”: {
}
},
{
“parameters”: {
“operation”: “download”,
“fileId”: {
“__rl”: true,
“value”: “https://drive.google.com/file/d/1DPQpmGx4GmAN7aH290ymVElu-OWZ4-dv/view?usp=drive_link”,
“mode”: “url”
},
“options”: {}
},
“type”: “n8n-nodes-base.googleDrive”,
“typeVersion”: 3,
“position”: [
800,
144
],
“id”: “6706b1d1-9ca3-406f-a929-e14a65f64cc5”,
“name”: “Download image”,
“credentials”: {
}
},
{
“parameters”: {},
“type”: “n8n-nodes-base.manualTrigger”,
“typeVersion”: 1,
“position”: [
160,
16
],
“id”: “30274d7f-ee98-478b-b174-55bc28f12c3c”,
“name”: “When clicking ‘Execute workflow’”
}
],
“connections”: {
“Split Out”: {
“main”: [
[
{
“node”: “Gemini nano banana 2”,
“type”: “main”,
“index”: 0
}
]
]
},
“Extract from CSV file”: {
“main”: [
[
{
“node”: “Split Out”,
“type”: “main”,
“index”: 0
}
]
]
},
“Gemini nano banana 2”: {
“main”: [
[
{
“node”: “Code in JavaScript1”,
“type”: “main”,
“index”: 0
}
]
]
},
“Code in JavaScript1”: {
“main”: [
[
{
“node”: “Upload file”,
“type”: “main”,
“index”: 0
}
]
]
},
“Download CSV”: {
“main”: [
[
{
“node”: “Extract from CSV file”,
“type”: “main”,
“index”: 0
}
]
]
},
“Download image”: {
“main”: [
[
{
“node”: “Gemini nano banana 2”,
“type”: “main”,
“index”: 0
}
]
]
},
“When clicking ‘Execute workflow’”: {
“main”: [
[
{
“node”: “Download image”,
“type”: “main”,
“index”: 0
},
{
“node”: “Download CSV”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “e851fae844e09d4d308a3bf809e2f9c7bff08d9b6b9da7343bb4674d021f1d22”
}
}

second workflow

{
“nodes”: [
{
“parameters”: {},
“id”: “c08f5998-fa21-48c0-8d31-9ef8f15507db”,
“name”: “Manual Trigger”,
“type”: “n8n-nodes-base.manualTrigger”,
“position”: [
-1408,
144
],
“typeVersion”: 1
},
{
“parameters”: {
“jsCode”: “return [\n { json: { branch: ‘csv’} },\n { json: { branch: ‘image’} }\n];\n”
},
“id”: “48351256-1dce-4fb0-9215-02d2fd101fc7”,
“name”: “Code (Split)”,
“type”: “n8n-nodes-base.code”,
“position”: [
-1248,
144
],
“typeVersion”: 2
},
{
“parameters”: {
“operation”: “download”,
“fileId”: {
“__rl”: true,
“value”: “1W5irR95gFudPwf1ZbBxRv_wHzXaAdemE”,
“mode”: “id”
},
“options”: {}
},
“id”: “31cbdab3-1102-4aa7-9f62-5ae76e7c67b7”,
“name”: “Download CSV”,
“type”: “n8n-nodes-base.googleDrive”,
“position”: [
-512,
-64
],
“typeVersion”: 3,
},
{
“parameters”: {
“operation”: “download”,
“fileId”: {
“__rl”: true,
“value”: “1DPQpmGx4GmAN7aH290ymVElu-OWZ4-dv”,
“mode”: “id”
},
“options”: {}
},
“id”: “392cbd16-993f-41dc-b9ec-4126d1fdfa44”,
“name”: “Download Image”,
“type”: “n8n-nodes-base.googleDrive”,
“position”: [
-576,
336
],
“typeVersion”: 3,
},
{
“parameters”: {
“mode”: “combine”,
“fieldsToMatchString”: “key”,
“options”: {}
},
“id”: “47680191-d896-4de5-a4f2-bbba3c58ed66”,
“name”: “Merge CSV + Image”,
“type”: “n8n-nodes-base.merge”,
“position”: [
160,
96
],
“typeVersion”: 3.2
},
{
“parameters”: {
“assignments”: {
“assignments”: [
{
“id”: “529c0c1e-04fd-473e-94c4-bb54e7edccda”,
“name”: “key”,
“value”: “1”,
“type”: “string”
}
]
},
“options”: {}
},
“id”: “339c5b7a-2f62-4ac4-bfb6-670d4ecb3f9e”,
“name”: “Set CSV Key”,
“type”: “n8n-nodes-base.set”,
“position”: [
0,
-64
],
“typeVersion”: 3.4
},
{
“parameters”: {
“assignments”: {
“assignments”: [
{
“id”: “d5b0919d-63c7-4e18-b601-b17f035e8d6f”,
“name”: “key”,
“value”: “1”,
“type”: “string”
}
]
},
“options”: {}
},
“id”: “705ae5de-45f8-4210-b553-e3152ea22a67”,
“name”: “Set Image Key”,
“type”: “n8n-nodes-base.set”,
“position”: [
-304,
336
],
“typeVersion”: 3.4
},
{
“parameters”: {
“fieldToSplitOut”: “prompt”,
“include”: “selectedOtherFields”,
“fieldsToInclude”: “shotNumber”,
“options”: {}
},
“type”: “n8n-nodes-base.splitOut”,
“typeVersion”: 1,
“position”: [
-144,
-64
],
“id”: “de090296-6ddd-4397-a795-990dfe1927a4”,
“name”: “Split Out”
},
{
“parameters”: {
“options”: {}
},
“type”: “n8n-nodes-base.extractFromFile”,
“typeVersion”: 1,
“position”: [
-320,
-64
],
“id”: “dc29ee0b-bbf3-48db-bb58-53330ca142bf”,
“name”: “Extract from CSV file”
},
{
“parameters”: {
“rules”: {
“values”: [
{
“conditions”: {
“options”: {
“caseSensitive”: true,
“leftValue”: “”,
“typeValidation”: “strict”,
“version”: 2
},
“conditions”: [
{
“id”: “60213fe2-af7b-4d5d-a473-5f3109ed0a4a”,
“leftValue”: “={{$json.branch}}”,
“rightValue”: “csv”,
“operator”: {
“type”: “string”,
“operation”: “equals”,
“name”: “filter.operator.equals”
}
}
],
“combinator”: “and”
}
},
{
“conditions”: {
“options”: {
“caseSensitive”: true,
“leftValue”: “”,
“typeValidation”: “strict”,
“version”: 2
},
“conditions”: [
{
“id”: “709bc63d-0735-42b7-82aa-d54715661461”,
“leftValue”: “={{$json.branch}}”,
“rightValue”: “image”,
“operator”: {
“type”: “string”,
“operation”: “equals”,
“name”: “filter.operator.equals”
}
}
],
“combinator”: “and”
}
}
]
},
“options”: {}
},
“type”: “n8n-nodes-base.switch”,
“typeVersion”: 3.3,
“position”: [
-1040,
144
],
“id”: “ed2f3788-7164-416d-874e-651da1bdc2f2”,
“name”: “Switch”,
“alwaysOutputData”: false,
“retryOnFail”: false,
“executeOnce”: false
},
{
“parameters”: {
“resource”: “image”,
“operation”: “edit”,
“prompt”: “=genera un fotogramma a partire dall’immagine in input dal seguente prompt: {{ $(‘Split Out’).item.json.prompt }}”,
“images”: {
“values”: [
{
“binaryPropertyName”: “=”
}
]
},
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.googleGemini”,
“typeVersion”: 1,
“position”: [
352,
96
],
“id”: “9458cf0f-ee0b-43ed-ae38-819d29509d7e”,
“name”: “Edit an image”,
“credentials”: {

}
],
“connections”: {
“Manual Trigger”: {
“main”: [
[
{
“node”: “Code (Split)”,
“type”: “main”,
“index”: 0
}
]
]
},
“Code (Split)”: {
“main”: [
[
{
“node”: “Switch”,
“type”: “main”,
“index”: 0
}
]
]
},
“Download CSV”: {
“main”: [
[
{
“node”: “Extract from CSV file”,
“type”: “main”,
“index”: 0
}
]
]
},
“Download Image”: {
“main”: [
[
{
“node”: “Set Image Key”,
“type”: “main”,
“index”: 0
}
]
]
},
“Merge CSV + Image”: {
“main”: [
[
{
“node”: “Edit an image”,
“type”: “main”,
“index”: 0
}
]
]
},
“Set CSV Key”: {
“main”: [
[
{
“node”: “Merge CSV + Image”,
“type”: “main”,
“index”: 0
}
]
]
},
“Set Image Key”: {
“main”: [
[
{
“node”: “Merge CSV + Image”,
“type”: “main”,
“index”: 1
}
]
]
},
“Split Out”: {
“main”: [
[
{
“node”: “Set CSV Key”,
“type”: “main”,
“index”: 0
}
]
]
},
“Extract from CSV file”: {
“main”: [
[
{
“node”: “Split Out”,
“type”: “main”,
“index”: 0
}
]
]
},
“Switch”: {
“main”: [
[
{
“node”: “Download CSV”,
“type”: “main”,
“index”: 0
}
],
[
{
“node”: “Download Image”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “e851fae844e09d4d308a3bf809e2f9c7bff08d9b6b9da7343bb4674d021f1d22”
}
}

Hy @Andrea_Olivieri !

Tried to copy your json into my Workflow, but it says is invalid… anyway, I think you should use a Merge node(append 2 inputs), and is not necessary the split .

Can you try this way :

Ciao!

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