I am trying to use an HTTP request to call on the OpenAI image edit api to generate some images.
I always get the error below after i execute the request:
The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
n8n version
1.111.0 (Self Hosted)
Stack trace
TypeError: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined at Function.from (node:buffer:325:9) at parametersToKeyValue (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected]_asn1.js@5_afd197edb2c1f848eae21a96a97fab23/node_modules/n8n-nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts:399:28) at prepareRequestBody (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected]_asn1.js@5_afd197edb2c1f848eae21a96a97fab23/node_modules/n8n-nodes-base/nodes/HttpRequest/GenericFunctions.ts:264:25) at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected]_asn1.js@5_afd197edb2c1f848eae21a96a97fab23/node_modules/n8n-nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts:418:53) at WorkflowExecute.executeNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_08b575bec2313d5d8a4cc75358971443/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1254:31) at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_08b575bec2313d5d8a4cc75358971443/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1428:22) at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_08b575bec2313d5d8a4cc75358971443/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1760:38 at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@[email protected]_@[email protected]_08b575bec2313d5d8a4cc75358971443/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2337:11
Please, can someone assist with a possible solution? I have attached a screenshot of what it looks like
It appears that the image field you’re sending is undefined — the error is literally telling you that it tried to use Buffer.from(undefined). You need to pass the actual uploaded file binary into the HTTP Request node.
I had a look at your workflow. The main issue is with how the HTTP Request node is picking up the file.
Easiest fix: you don’t really need that Code node at all. Just connect the HTTP Request node directly to your Product Data form node. In the body parameters, set the file field to use the binary key Upload_product_image (that’s the name coming straight from the form). This way the API will get the file as-is and it should work fine.
If you do want to keep the Code node in between, then the code needs a small tweak so it copies/renames the binary properly. Right now it’s dropping the file, which is why the HTTP node sees undefined. Basically, the Code node has to take Upload_product_image and expose it again as image (or whatever field name you want), then the HTTP node can use that key.
So short version:
Option A: Skip the Code node, map Upload_product_image directly in the HTTP node.
Option B: Fix the Code node so it re-outputs the binary under the right key (image), then use that in the HTTP node.
Try Option A first — it’s simpler and should just work.
Trying to reference a binary from a remote node is not something you can currently do, so merging is one way to do it. For that you can use a Merge node and bring that binary to where you need to use it [fixed below ]
You don’t want to be putting that API key into the field in clear text to begin with. Create a credential with openai and use that in the HTTP Request node.