How do I use variables in the "Input Data Field Name" area?

Hello, I have a requirement to send a group of attachments to DeepL for translation. I used a loop, and the name of the binary is dynamic. I cannot know how many attachments there are each time the script runs, so I need to use {{$input.item.binary}} or the extracted fileName for passing the value. However, when I use the variable, it always prompts an error: “The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined.” What expression should I use to correctly tell the HTTP request the binary file name? Thank you for your guidance!

Here’s a screenshot of me:

Here’s a worklfow of me:

Information on your n8n setup

  • n8n version:1.98.2
  • Database (default: SQLite):default
  • n8n EXECUTIONS_PROCESS setting (default: own, main):won
  • Running n8n via (Docker, npm, n8n cloud, desktop app):Docker
  • Operating system:mac os

Hi,

What is in your JSON tab (left)? Something like this?

“binary”: {
“data_0”: {
“fileName”: “error.jpg”,

}
}

The name (e.g. data_0) must be stored in the HTTP request node. So in the ‘name’ field

1 Like

Yes, I can use data_0, but when the workflow runs, the number of attachments is not fixed, and sometimes I don’t know how many attachments need to be processed, but I need to request each attachment separately. So I need to use variable names in the http node. When I use the variable name, I get an error.

I have not looked at the deepl documentation yet, but do you need to make a http call per attachment? Or do you need to submit all files in a single http call?

1 Like

Yes, I need to make a separate http call for each attachment。

Oh ok great then this should be fairly easy. So does your binaries have names like data_0, data_1, etc? It looks like in the code block you are handling them correct by getting the Object.keys. I would maybe recommend using the Loop node. Once you have your binaries split out into an array, enter the Loop node and then put your http node inside there. This way you can easily manipulate each binary by getting each files properties for calling the http node

我使用了{{ $json.fileName }}、{{$item.binary.data_0.fileName}}、{{Object.keys($binary).split(‘,’)}}但是都报错“The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined.” :smiling_face_with_tear:

I need to run out now, but I can create an example when I get back later today if you have not been helped by then.

But for now I can tell you that this parameter cant be an expression as it has to be the field name IE data_0

However since you are splitting the binaries, it should be this: Object.keys($binary) for the specific one you’re looping over

I tried Object.keys ($binary) but it still doesn’t work, I really need your example! Waiting for your reply.

I think I fixed the issue, and under my debugging I found out that it was my file that was problematic and it was written correctly, just that my file was faulty and caused the error. I made a mistake in the previous node to modify the file name and the file was unavailable.

1 Like