# Set Binary Data with Code node

**URL:** <https://community.n8n.io/t/set-binary-data-with-code-node/39576>\
**Category:** Questions\
**Tags:** code\
**Created:** [February 1, 2024, 10:44pm UTC](https://community.n8n.io/t/set-binary-data-with-code-node/39576 "2024-02-01T22:44:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MCPCN](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mcpcn/32/34881_2.png) [@MCPCN](https://community.n8n.io/u/MCPCN)\
**Post date:** [February 1, 2024, 10:44pm UTC](https://community.n8n.io/t/set-binary-data-with-code-node/39576/1 "2024-02-01T22:44:44Z")

</div>

## Describe the problem/error/question

I’m using the Code node and have successfully used this.helpers.getBinaryDataBuffer(0, ‘data’); to read binary data from a previous file read node, then process it into a “buffer” variable.

I can’t find a way to return the “buffer” as a file from the code node.

Using prepareBinaryData gives an “ERROR: body.once is not a function [line 15]” error; is this the right way to do it?

```auto
await this.helpers.prepareBinaryData(
   buffer,
  'test',
);

```

If not, can we confirm how to return “buffer” as a downloadable file? I’ve tried this, it returns stuff in the Output pane, but it seems to be doing it bit by bit… guess I need to read the whole buffer into something first:

```auto
return {json: {}, binary:buffer};

```

## Information on your n8n setup

- **n8n version:** Latest
- **Database (default: SQLite):** Postgres
- **n8n EXECUTIONS\_PROCESS setting (default: own, main):**
- **Running n8n via (Docker, npm, n8n cloud, desktop app):** Docker
- **Operating system:** Linux

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [February 12, 2024, 3:49pm UTC](https://community.n8n.io/t/set-binary-data-with-code-node/39576/3 "2024-02-12T15:49:32Z")

</div>

Hi @MCPCN, I am so sorry you are having trouble.

The syntax `await this.helpers.prepareBinaryData(myBuffer, 'filename.ext')`, however, looks correct to me.

I have just tested this using the below workflow on n8n 1.28.0:

This produced the below result:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/0/d/0d4b139d55c9fedaf292433af80f9cbf203991ad.png)

The file preview confirms this is a valid file:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/2/2/22fd541e660c34f97930e8f88c3f385b2fca8d4e.png)

Perhaps you can share a workflow using which your problem can be reproduced?

---

<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:** [May 12, 2024, 3:49pm UTC](https://community.n8n.io/t/set-binary-data-with-code-node/39576/4 "2024-05-12T15:49:46Z")

</div>

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