ERROR: Label 'data' has already been declared

Quick question, I’m getting the error:

I’m trying to iterate over some previous results and I can get it working for a single time but not iterating.

I have to have the format

  binary: {
    data: {
      data:
const response = [];

for (const item of items) {
  binary: {
    data: {
      data: $node['Merge3'].json.company_logo,
      mimeType: "image/png",
      fileExtension: 'png',
      fileName: $node['Merge3'].json.image_name+"_victim.png"
    }
  }
  }
  response.push({
    json: {
        binary
     }
    }
  )

return response;

any ideas where I’m going wrong?

There are a couple of issues with that code.

1 - company logo is probably a string and it needs to be a base64 encoded string. You might need to do something like Buffer.from($node['Merge3'].json.company_logo).toString('base64')

2 -In the response binary it’s within JSON, but it should be at the same level. Check the n8n data structure.

Also, depending on how the workflow is set up, you might not want to reference the data using $node['Merge3'].

its already in base64 format as company_logo

i’ll have a look at the link you sent, cheers

I’m getting different errors, not sure I’m fully understanding how to manipulate it with the correct structure. Man these functions nodes are hard work! :pensive:

ERROR: Unexpected token ':'

Stack

/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes:6
				mimeType: 'image/png',
				        ^

brain hurts, will have a google tomorrow

Ahh, yes, I had missed that. You are not creating a valid JSON object. You have to change your function node to something similar to:

const response = [];

for (const item of items) {
  response.push({
    json: {},
    binary: {
      data: {
        data: item.json.image,
        mimeType: "image/png",
        fileExtension: 'png',
        fileName: 'image.jpeg'
      } 
    }
  })
}
  
return response;
1 Like

ah that’s working better, just need to figure out why its 53 of the same first entry and image, rather than iterating through the inputs

Try dropping the const and see if that helps.

i stripped this one out and tried again,
image
same issue

removing the node reference solved it

const response = [];

for (const item of items) {
  response.push({
    json: {},
    binary: {
      data: {
        data: item.json.company_logo,
        mimeType: "image/png",
        fileExtension: 'png',
        fileName: item.json.image_name+"_victim.png",
      } 
    }
  })
}
  
return response;
1 Like