# $binary.audio becomes undefined in Code node after successful binary upload via Webhook node

**URL:** <https://community.n8n.io/t/binary-audio-becomes-undefined-in-code-node-after-successful-binary-upload-via-webhook-node/189688>\
**Category:** Questions\
**Created:** [September 17, 2025, 1:38pm UTC](https://community.n8n.io/t/binary-audio-becomes-undefined-in-code-node-after-successful-binary-upload-via-webhook-node/189688 "2025-09-17T13:38:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![juhyeon\_PARK](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/juhyeon_park/32/54369_2.png) [@juhyeon\_PARK](https://community.n8n.io/u/juhyeon_PARK)\
**Post date:** [September 17, 2025, 1:38pm UTC](https://community.n8n.io/t/binary-audio-becomes-undefined-in-code-node-after-successful-binary-upload-via-webhook-node/189688/1 "2025-09-17T13:38:05Z")

</div>

```auto
<!-- Hey! The fastest way to find solutions is by using the 🔎 search function at the upper right.
If your question hasn't been asked before, please follow the template below. Skip the questions that are not relevant to you. -->

```

**[Workflow Purpose]**

- **To receive a meeting recording (or uploaded audio file),**

- **Automatically perform speech-to-text (STT) transcription and summarization,**

- **And send the results via email or provide a download link if needed.**

* * *

**[Data Flow and Processing Steps]**

1. **User Interface**

2. **Webhook: Upload (POST /meeting/upload)**

3. **Code: Find binary data**

4. **Code: Validate & Pick Binary1**

5. **HTTP: Whisper STT (OpenAI, etc.)**

6. **Code: Static Upsert Part & Merge**

7. **Code: Check Text Length**

8. **HTTP: GPT Summarize (Chat Completions)**

9. **Code: Pick Summary**

10. **Set: Carry Payload & Send Email**

* * *

**[Data Creation and Transfer Summary]**

- **Binary data:** The file is received by the Webhook, the key is changed to audio in a Code node, and all subsequent nodes reference it as audio.

- **JSON data:** Each step passes along necessary metadata (email, group\_id, part\_index, etc.) and the text/summary results as JSON.

- **Error handling:** If validation fails at any step, the workflow stops with an error message or returns a specific error response.

## Describe the problem/error/question

1. Webhook node receives binary data correctly (key: “data”, MIME: multipart/form-data, filename and size normal).

2. In the first Code node, I remap the binary key from “data” to “audio” using:

3. In the next Code node, $binary.audio is undefined, causing an error: “Binary data is empty or invalid. Size: undefined”.

## What is the error message (if any)?

> **Problem in node ‘Code: Validate & Pick Binary1‘**
> 
> No binary data found in input. Check previous node output. [line 2]

## Please share your workflow

## Share the output returned by the last node

```auto
<!-- If you need help with data transformations, please also share your expected output. -->

```

```auto
[Workflow Structure]
- Webhook → Code: Find binary data (remaps to 'audio') → Code: Validate & Pick Binary1 (references $binary.audio, which is undefined).
- No intermediate nodes that could lose binary data (e.g., no Split, Merge, IF).
- All nodes are set to "runOnceForEachItem" execution mode.
[Attempted Solutions]
- Changed the return format in Code nodes to a single object instead of an array.
- Ensured all nodes have the same execution mode ("runOnceForEachItem").
- Verified binary data in each node's input/output tabs; the binary exists in the Webhook output but disappears after remapping.

```

## Information on your n8n setup

- **n8n version:** 1.109.1-exp.0 (Cloud)
- **Database (default: SQLite): -**
- **n8n EXECUTIONS\_PROCESS setting (default: own, main): -**
- **Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud**
- **Operating system: -**

---

<div class="post-metadata">

**Author:** ![krisn0x](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/krisn0x/32/118504_2.png) [@krisn0x](https://community.n8n.io/u/krisn0x)\
**Post date:** [September 17, 2025, 2:58pm UTC](https://community.n8n.io/t/binary-audio-becomes-undefined-in-code-node-after-successful-binary-upload-via-webhook-node/189688/2 "2025-09-17T14:58:00Z")

</div>

Whenever you are assigning binary data to a variable, you want to do it like this:

```auto
const bin = $input.item.binary || {};

```

not like this:

```auto
const bin = $binary || {};

```

Here is the changed code that works for me, you can copy these 2 nodes directly from here and paste them in your flow to test them out:

---

<div class="post-metadata">

**Author:** ![jabbson](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jabbson/32/87328_2.png) [@jabbson](https://community.n8n.io/u/jabbson)\
**Post date:** [September 17, 2025, 3:34pm UTC](https://community.n8n.io/t/binary-audio-becomes-undefined-in-code-node-after-successful-binary-upload-via-webhook-node/189688/3 "2025-09-17T15:34:21Z")

</div>

Hey @juhyeon_PARK hope all is good. First thing I would try is use a v2 version of the Webhook node,

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/b/e/be2e2f3b83f5963f8e499cf27e847c5af3c4d4ad.png)

which allows to set the name of the binary property name (1). Unfortunately the node always appends the binary index to the filename, even if there is only one file present.

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/e/5/e551fb621bff8f45a78decb12c5df357288d7a28.png)

> [@juhyeon\_PARK](#):
>
> **Code: Find binary data**
> 
> - Changes the binary key from data to audio.
> - Ensures all subsequent nodes can reference the binary as audio.

If this is all you need, I would do

```javascript
function renameBinary(obj, from, to) {
  if (!(from in obj) || from === to) return obj;
  obj[to] = obj[from];
  delete obj[from];
  return obj;
}

renameBinary($input.item.binary, "data", "audio");

return $input.item

```

for the second code, see if you like the following:

```javascript
const audio = $input.item?.binary?.audio;
if (!audio) {
  throw new Error('No binary "audio" found. Please check the previous node.');
}

const EXT_TO_MIME = {
  webm: 'audio/webm',
  mp3: 'audio/mpeg',
  mpeg: 'audio/mpeg',
  mpga: 'audio/mpeg',
  mp4: 'audio/mp4',
  wav: 'audio/wav',
  ogg: 'audio/ogg',
  oga: 'audio/ogg',
  flac: 'audio/flac',
  m4a: 'audio/m4a',
};

const ALIAS_TO_CANON = { mpeg: 'mp3', mpga: 'mp3', oga: 'ogg' };
const OK = new Set(Object.keys(EXT_TO_MIME));

const name = audio.fileName ?? 'audio';
const dot = name.lastIndexOf('.');
const base = dot > -1 ? name.slice(0, dot) : name;
const rawExt = (dot > -1 ? name.slice(dot + 1) : '').toLowerCase();

const fromMime = (() => {
  const m = (audio.mimeType || '').toLowerCase();
  if (!m) return '';
  
  if (m.includes('webm')) return 'webm';
  if (m.includes('mp4')) return 'mp4';
  if (m.includes('mpeg') || m.includes('mp3') || m.includes('mpga')) return 'mp3';
  if (m.includes('wav')) return 'wav';
  if (m.includes('ogg') || m.includes('oga')) return 'ogg';
  if (m.includes('flac')) return 'flac';
  if (m.includes('m4a')) return 'm4a';
  return '';
})();

const pick = (ext) => {
  if (!ext) return '';
  const canon = ALIAS_TO_CANON[ext] ?? ext;
  return OK.has(canon) ? canon : '';
};

const finalExt = pick(rawExt) || pick(fromMime) || 'webm';
const finalMime = EXT_TO_MIME[ALIAS_TO_CANON[finalExt] ?? finalExt] || audio.mimeType || 'application/octet-stream';

audio.fileName = `${base || 'audio'}.${finalExt}`;
audio.mimeType = finalMime;

return { json: { _binKey: 'audio' }, binary: { audio } };

```

One problem in your second code was that the return of the code node with “Run Once for Each Item” needs to be an object, not an array. Also the above code has some minor improvements, namely - it uses a single source of truth - one `EXT_TO_MIME` map (+ small alias map). No big `switch`/`if` ladders. The parseing is a bit tighter, no need for extra helpers for name splitting. Clear priority for the final extension - filename ext (if valid) over mime-derived ext over default `webm`.

Final:

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [September 24, 2025, 3:34pm UTC](https://community.n8n.io/t/binary-audio-becomes-undefined-in-code-node-after-successful-binary-upload-via-webhook-node/189688/4 "2025-09-24T15:34:59Z")

</div>

Closed on September 24, 2025, 3:34pm UTC

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