Using {{$runIndex}} to save base64 shows me an undefined file

I downloaded 2 files

And I am runnign a loop to save them in different names “generated_image_{{$runIndex}}” using a loop

It does save them as generated_image_0 and generated_image_1, however when I am trying to use the second one (generated_image_1 it shows it as a null or undefined.

What can it be?

1 Like

Share the output returned by the last node

“output”: “undeffined”

Expected output

“output”: “the model image base64

Information on your n8n setup

  • n8n version: 1.107.3

  • Database (default: SQLite): default

  • n8n EXECUTIONS_PROCESS setting (default: own, main): sorry have no idea

  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud

  • Operating system:

Please can you share your workflow in a code block so we can try and see what the issue is?

Of course.

How can I share it without the credentials?

Here is the lfow:

</>

{
“nodes”: [
{
“parameters”: {
“httpMethod”: “POST”,
“path”: “148270d8-f42b-41ef-8334-688d4d9da647”,
“options”: {}
},
“type”: “n8n-nodes-base.webhook”,
“typeVersion”: 2.1,
“position”: [
-96,
-80
],
“id”: “13fd0db3-eef1-4d38-a9a0-b159ef8f9c3c”,
“name”: “Webhook”,
“webhookId”: “148270d8-f42b-41ef-8334-688d4d9da647”
},
{
“parameters”: {
“operation”: “toBinary”,
“sourceProperty”: “candidates[0].content.parts[0].inlineData.data”,
“binaryPropertyName”: “=generated_image”,
“options”: {
“fileName”: “generated_image2”
}
},
“type”: “n8n-nodes-base.convertToFile”,
“typeVersion”: 1.1,
“position”: [
1472,
-272
],
“id”: “8b060caf-e2cf-4abd-9ac9-8270b77f1e5c”,
“name”: “Save final results”
},
{
“parameters”: {
“url”: “={{ $json.url }}”,
“options”: {
“response”: {
“response”: {
“responseFormat”: “file”
}
}
}
},
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.2,
“position”: [
496,
-112
],
“id”: “39f26c04-6365-4b9a-94f3-ee371ed5de57”,
“name”: “HTTP Request”
},
{
“parameters”: {
“operation”: “binaryToPropery”,
“destinationKey”: “=generated_image_{{$runIndex}}”,
“options”: {}
},
“type”: “n8n-nodes-base.extractFromFile”,
“typeVersion”: 1,
“position”: [
1200,
32
],
“id”: “3aecd95e-2bcc-4ec6-8cf4-2fa4b70e8dd6”,
“name”: “Extract from File”
},
{
“parameters”: {
“assignments”: {
“assignments”: [
{
“id”: “e8249f97-507c-4162-9c2a-58ffe6dfff25”,
“name”: “change”,
“value”: “Create a professional e-commerce fashion photo. Take the cloth from the first image and let the model from the second image wear it. Generate a realistic, full-body shot of the model wearing the cloth, with the lighting and shadows adjusted to match the same environment of the model, the result should be the same model in the same environment wearnig the cloth”,
“type”: “string”
}
]
},
“options”: {}
},
“type”: “n8n-nodes-base.set”,
“typeVersion”: 3.4,
“position”: [
96,
-112
],
“id”: “f5f35748-61a5-47fa-b663-96cfc2a5bbfe”,
“name”: “Edit Fields8”
},
{
“parameters”: {
“jsCode”: “const images = $(‘Webhook’).first().json.body.images;\n\nreturn images.map(img => {\n return {\n json: {\n url: img.url,\n type: img.type\n }\n };\n});\n”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
288,
-80
],
“id”: “2698c469-3315-4385-a393-bea4921ff61e”,
“name”: “Code”
},
{
“parameters”: {
“options”: {}
},
“type”: “n8n-nodes-base.splitInBatches”,
“typeVersion”: 3,
“position”: [
736,
-96
],
“id”: “1b7f6c5b-78d1-4580-8e66-b0375c9cf5fa”,
“name”: “Loop Over Items”
},
{
“parameters”: {
“assignments”: {
“assignments”: [
{
“id”: “c84c58c3-3a8a-4e82-8414-ca602730eb97”,
“name”: “product”,
“value”: “={{ $json.generated_image_0 }}”,
“type”: “string”
},
{
“id”: “15448af7-97aa-40f5-a36b-3202cbac23ea”,
“name”: “model”,
“value”: “={{ $json.generated_image_1 }}”,
“type”: “string”
}
]
},
“options”: {}
},
“type”: “n8n-nodes-base.set”,
“typeVersion”: 3.4,
“position”: [
1024,
-192
],
“id”: “edc27be1-646c-4c1d-9edc-4964bbbafdcf”,
“name”: “Edit Fields”
},
{
“parameters”: {
“method”: “POST”,
“url”: “https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image-preview:generateContent”,
“sendHeaders”: true,
“headerParameters”: {
“parameters”: [
{
“name”: “x-goog-api-key”,
“value”: “yBa”
}
]
},
“sendBody”: true,
“specifyBody”: “json”,
“jsonBody”: "={\n “contents”: [\n {\n “parts”: [\n {\n “inline_data”: {\n “mime_type”: “image/png”,\n “data”: “{{ $json.product }}”\n }\n },\n {\n “inline_data”: {\n “mime_type”: “image/jpeg”,\n “data”: “{{ $json.model }}”\n }\n },\n {\n “text”: “{{ $(‘Edit Fields8’).item.json.change }}”\n }\n ]\n }\n ]\n} ",
“options”: {}
},
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.2,
“position”: [
1264,
-240
],
“id”: “68521d8d-60eb-41f0-a33e-48195acc7d5f”,
“name”: “Model wears the cloth”
}
],
“connections”: {
“Webhook”: {
“main”: [
[
{
“node”: “Edit Fields8”,
“type”: “main”,
“index”: 0
}
]
]
},
“HTTP Request”: {
“main”: [
[
{
“node”: “Loop Over Items”,
“type”: “main”,
“index”: 0
}
]
]
},
“Extract from File”: {
“main”: [
[
{
“node”: “Loop Over Items”,
“type”: “main”,
“index”: 0
}
]
]
},
“Edit Fields8”: {
“main”: [
[
{
“node”: “Code”,
“type”: “main”,
“index”: 0
}
]
]
},
“Code”: {
“main”: [
[
{
“node”: “HTTP Request”,
“type”: “main”,
“index”: 0
}
]
]
},
“Loop Over Items”: {
“main”: [
[
{
“node”: “Edit Fields”,
“type”: “main”,
“index”: 0
}
],
[
{
“node”: “Extract from File”,
“type”: “main”,
“index”: 0
}
]
]
},
“Edit Fields”: {
“main”: [
[
{
“node”: “Model wears the cloth”,
“type”: “main”,
“index”: 0
}
]
]
},
“Model wears the cloth”: {
“main”: [
[
{
“node”: “Save final results”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“pinData”: {
“Webhook”: [
{
“headers”: {
“host”: “n8n.roeeaizman.com”,
“user-agent”: “Deno/2.3.1”,
“content-length”: “637”,
“accept”: “/”,
“accept-encoding”: “gzip,br”,
“accept-language”: “*”,
“cdn-loop”: “deno;s=deno;d=f67vaeed9zzc”,
“content-type”: “application/json”,
“via”: “2.0 Caddy”,
“x-forwarded-for”: “35.236.74.252”,
“x-forwarded-host”: “n8n.roeeaizman.com”,
“x-forwarded-proto”: “https”
},
“params”: {},
“query”: {},
“body”: {
“project_id”: “68d2970ebce4185676a1a08e”,
“images”: [
{
“image_number”: 1,
“type”: “product”,
“url”: “https://base44.app/api/apps/68d25b21170607c38292d2b2/files/public/68d25b21170607c38292d2b2/3c5d46d2b_f59e29cbc_15e33569-dd21-4395-93d3-3331a17ab627.png”,
“order”: 1
},
{
“image_number”: 2,
“type”: “model”,
“url”: “https://base44.app/api/apps/68d25b21170607c38292d2b2/files/public/68d25b21170607c38292d2b2/efdbc4c77_model.jpg”
}
],
“total_product_images”: 1,
“total_images”: 2,
“timeout”: 300,
“callback_instructions”: “Generate high-quality fashion visualizations showing the model wearing the products from multiple angles including front, side, and back views.”
},
“webhookUrl”: “https://n8n.roeeaizman.com/webhook-test/13dbf528-a666-4d82-bf3e-5998da0f8b1e”,
“executionMode”: “test”
}
]
},
“meta”: {
“instanceId”: “3efbe569e558a18a54352d7073a74807fb3f352c1b3f6b3fdfb719b0cd89fe51”
}
}

</>

<{
“nodes”: [
{
“parameters”: {
“httpMethod”: “POST”,
“path”: “148270d8-f42b-41ef-8334-688d4d9da647”,
“options”: {}
},
“type”: “n8n-nodes-base.webhook”,
“typeVersion”: 2.1,
“position”: [
-96,
-80
],
“id”: “13fd0db3-eef1-4d38-a9a0-b159ef8f9c3c”,
“name”: “Webhook”,
“webhookId”: “148270d8-f42b-41ef-8334-688d4d9da647”
},
{
“parameters”: {
“operation”: “toBinary”,
“sourceProperty”: “candidates[0].content.parts[0].inlineData.data”,
“binaryPropertyName”: “=generated_image”,
“options”: {
“fileName”: “generated_image2”
}
},
“type”: “n8n-nodes-base.convertToFile”,
“typeVersion”: 1.1,
“position”: [
1472,
-272
],
“id”: “8b060caf-e2cf-4abd-9ac9-8270b77f1e5c”,
“name”: “Save final results”
},
{
“parameters”: {
“url”: “={{ $json.url }}”,
“options”: {
“response”: {
“response”: {
“responseFormat”: “file”
}
}
}
},
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.2,
“position”: [
496,
-112
],
“id”: “39f26c04-6365-4b9a-94f3-ee371ed5de57”,
“name”: “HTTP Request”
},
{
“parameters”: {
“operation”: “binaryToPropery”,
“destinationKey”: “=generated_image_{{$runIndex}}”,
“options”: {}
},
“type”: “n8n-nodes-base.extractFromFile”,
“typeVersion”: 1,
“position”: [
1200,
32
],
“id”: “3aecd95e-2bcc-4ec6-8cf4-2fa4b70e8dd6”,
“name”: “Extract from File”
},
{
“parameters”: {
“assignments”: {
“assignments”: [
{
“id”: “e8249f97-507c-4162-9c2a-58ffe6dfff25”,
“name”: “change”,
“value”: “Create a professional e-commerce fashion photo. Take the cloth from the first image and let the model from the second image wear it. Generate a realistic, full-body shot of the model wearing the cloth, with the lighting and shadows adjusted to match the same environment of the model, the result should be the same model in the same environment wearnig the cloth”,
“type”: “string”
}
]
},
“options”: {}
},
“type”: “n8n-nodes-base.set”,
“typeVersion”: 3.4,
“position”: [
96,
-112
],
“id”: “f5f35748-61a5-47fa-b663-96cfc2a5bbfe”,
“name”: “Edit Fields8”
},
{
“parameters”: {
“jsCode”: “const images = $(‘Webhook’).first().json.body.images;\n\nreturn images.map(img => {\n return {\n json: {\n url: img.url,\n type: img.type\n }\n };\n});\n”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
288,
-80
],
“id”: “2698c469-3315-4385-a393-bea4921ff61e”,
“name”: “Code”
},
{
“parameters”: {
“options”: {}
},
“type”: “n8n-nodes-base.splitInBatches”,
“typeVersion”: 3,
“position”: [
736,
-96
],
“id”: “1b7f6c5b-78d1-4580-8e66-b0375c9cf5fa”,
“name”: “Loop Over Items”
},
{
“parameters”: {
“assignments”: {
“assignments”: [
{
“id”: “c84c58c3-3a8a-4e82-8414-ca602730eb97”,
“name”: “product”,
“value”: “={{ $json.generated_image_0 }}”,
“type”: “string”
},
{
“id”: “15448af7-97aa-40f5-a36b-3202cbac23ea”,
“name”: “model”,
“value”: “={{ $json.generated_image_1 }}”,
“type”: “string”
}
]
},
“options”: {}
},
“type”: “n8n-nodes-base.set”,
“typeVersion”: 3.4,
“position”: [
1024,
-192
],
“id”: “edc27be1-646c-4c1d-9edc-4964bbbafdcf”,
“name”: “Edit Fields”
},
{
“parameters”: {
“method”: “POST”,
“url”: “https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image-preview:generateContent”,
“sendHeaders”: true,
“headerParameters”: {
“parameters”: [
{
“name”: “x-goog-api-key”,
“value”: “yBa”
}
]
},
“sendBody”: true,
“specifyBody”: “json”,
“jsonBody”: "={\n “contents”: [\n {\n “parts”: [\n {\n “inline_data”: {\n “mime_type”: “image/png”,\n “data”: “{{ $json.product }}”\n }\n },\n {\n “inline_data”: {\n “mime_type”: “image/jpeg”,\n “data”: “{{ $json.model }}”\n }\n },\n {\n “text”: “{{ $(‘Edit Fields8’).item.json.change }}”\n }\n ]\n }\n ]\n} ",
“options”: {}
},
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.2,
“position”: [
1264,
-240
],
“id”: “68521d8d-60eb-41f0-a33e-48195acc7d5f”,
“name”: “Model wears the cloth”
}
],
“connections”: {
“Webhook”: {
“main”: [
[
{
“node”: “Edit Fields8”,
“type”: “main”,
“index”: 0
}
]
]
},
“HTTP Request”: {
“main”: [
[
{
“node”: “Loop Over Items”,
“type”: “main”,
“index”: 0
}
]
]
},
“Extract from File”: {
“main”: [
[
{
“node”: “Loop Over Items”,
“type”: “main”,
“index”: 0
}
]
]
},
“Edit Fields8”: {
“main”: [
[
{
“node”: “Code”,
“type”: “main”,
“index”: 0
}
]
]
},
“Code”: {
“main”: [
[
{
“node”: “HTTP Request”,
“type”: “main”,
“index”: 0
}
]
]
},
“Loop Over Items”: {
“main”: [
[
{
“node”: “Edit Fields”,
“type”: “main”,
“index”: 0
}
],
[
{
“node”: “Extract from File”,
“type”: “main”,
“index”: 0
}
]
]
},
“Edit Fields”: {
“main”: [
[
{
“node”: “Model wears the cloth”,
“type”: “main”,
“index”: 0
}
]
]
},
“Model wears the cloth”: {
“main”: [
[
{
“node”: “Save final results”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“pinData”: {
“Webhook”: [
{
“headers”: {
“host”: “n8n.roeeaizman.com”,
“user-agent”: “Deno/2.3.1”,
“content-length”: “637”,
“accept”: “/”,
“accept-encoding”: “gzip,br”,
“accept-language”: “*”,
“cdn-loop”: “deno;s=deno;d=f67vaeed9zzc”,
“content-type”: “application/json”,
“via”: “2.0 Caddy”,
“x-forwarded-for”: “35.236.74.252”,
“x-forwarded-host”: “n8n.roeeaizman.com”,
“x-forwarded-proto”: “https”
},
“params”: {},
“query”: {},
“body”: {
“project_id”: “68d2970ebce4185676a1a08e”,
“images”: [
{
“image_number”: 1,
“type”: “product”,
“url”: “https://base44.app/api/apps/68d25b21170607c38292d2b2/files/public/68d25b21170607c38292d2b2/3c5d46d2b_f59e29cbc_15e33569-dd21-4395-93d3-3331a17ab627.png”,
“order”: 1
},
{
“image_number”: 2,
“type”: “model”,
“url”: “https://base44.app/api/apps/68d25b21170607c38292d2b2/files/public/68d25b21170607c38292d2b2/efdbc4c77_model.jpg”
}
],
“total_product_images”: 1,
“total_images”: 2,
“timeout”: 300,
“callback_instructions”: “Generate high-quality fashion visualizations showing the model wearing the products from multiple angles including front, side, and back views.”
},
“webhookUrl”: “https://n8n.roeeaizman.com/webhook-test/13dbf528-a666-4d82-bf3e-5998da0f8b1e”,
“executionMode”: “test”
}
]
},
“meta”: {
“instanceId”: “3efbe569e558a18a54352d7073a74807fb3f352c1b3f6b3fdfb719b0cd89fe51”
}
}/>

Please try sharing it once more like so

I cant share it as the canvas, I don’t know how to do it so I dont want to share again.
Only if I understand how to do it right

You can either follow my gif example, or you can export it as JSON and upload it to G Drive. None of these methods will export your credentials so don’t worry.

Edit: here it is again, my bad

Hey.

This is my workflow:

Done @krisn0x and @Wouter_Nigrini

Here you go! Feel free to mark this as Solution if it helped :slight_smile:

3 Likes

Wow!!!

So Why it happened to me as it was undefined?

Just an aggregate

Thanks a lot @krisn0x

The data is there, but it’s arriving in separate items. While in your Set Fields node you try to get all items at the same time. There is a difference in n8n whenever data is split into items vs all items into 1 object. You can manipulate this with the Split out and Aggregate nodes :slight_smile:

Anytime! :heart: Like if it helped :white_check_mark: Mark as Solution if I solved it

I tried to split before.Anyway Thanks a lot, however I still cannot send the binary to the respond of the webhook.Any case you understand why?

what’s the issue there? can you grab a screenshot of the problematic node with its input and output?

1 Like

Hey @krisn0x thanks for being with me :slight_smile:

I am getting a webhook and wait for the last respond to webhook to send the generated image from nano banana

the problem is that the client (base44 or postman) does not wait for the response of the respond to webhook.:

should be with some more cotent inside

The credentials should be stripped unless you had them hardcoded in headers etc, then you must just delete it first

1 Like