Setup of code node and loop over item node

Describe the problem/error/question

i am creating a workflow which include the main purpose to allow me upload receipt using the n8n on form submission for several documents, with code node to capture the document information.
As the node can only handle 1 item every time, add loop over item after it.
later to pass on to Google gemini node which accept binary file to analyze the document to analyse the receipt information,item, title and output as json format, and the result json will be processed by code node, and then the parsed information will be append to google sheet for input.
question 1: I have no idea for what code should be input in the code nodes should be input, so it can generate in binary file for gemini for analyse document?

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.104.1
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
  • Operating system: windows 11
1 Like

Hi to handle multiple binary files you can add the following code in your first code node:

const data = $input.last().json
const binaryData = $input.last().binary

let output = []

Object.keys(binaryData).forEach( b => {
  output.push({
    json: data,
    binary: { data: binaryData[b]}
  })
})

return output

Then you can use for example the extract text from pdf function, if you upload pdf files.
No need for the loop node in this case.

2 Likes

Thanks. I try to upload image and it can read the image files and parse the json.

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