# How to return binary data in custom node

**URL:** <https://community.n8n.io/t/how-to-return-binary-data-in-custom-node/118067>\
**Category:** Questions\
**Tags:** core, data-transformation, node, http-request\
**Created:** [May 20, 2025, 1:21pm UTC](https://community.n8n.io/t/how-to-return-binary-data-in-custom-node/118067 "2025-05-20T13:21:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexnemes](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@alexnemes](https://community.n8n.io/u/alexnemes)\
**Post date:** [May 20, 2025, 1:21pm UTC](https://community.n8n.io/t/how-to-return-binary-data-in-custom-node/118067/1 "2025-05-20T13:21:23Z")

</div>

## Describe the problem/error/question

Can you please help me with my code for returning binary data?

My custom node binary data only outputs 1 item even if it receives multiple inputs. I need help to correctly populate the binary property for the output, with all the files showing correctly.

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

No error, I want to correctly return the binary property files for my custom node. Currently it only creates 1 binary item which is the 1st input received. It returns correctly the json items but the binary property only contains 1 file (the 1st one processed).

## Please share your workflow

```auto
// generateReportFromReportDefinition
if (resource === 'report') {
	if (operation === 'generateReportFromReportDefinition') {

		let endpoint = `https://portal.mobilefieldreport.com/mfr/Report`

		const ServiceRequestUI = this.getNodeParameter('ServiceRequest', i) as IDataObject;
		const ServiceRequestId = ServiceRequestUI.value
		const ReportDefinitionCode = this.getNodeParameter('ReportDefinitionCode', i) as string;

		body.ServiceRequestId = ServiceRequestId
		body.ReportDefinitionCode = ReportDefinitionCode
		body.IsInvoice = false

		const optionsFirstRequest = {
			method: 'POST',
			body: body,
			qs,
			uri: endpoint,
			json: true,
			useQuerystring: true,
		} satisfies IRequestOptions;

		console.log(optionsFirstRequest)

	let responseDataFirstRequest = await this.helpers.requestWithAuthentication.call(
			this,
			'mfrApi',
			optionsFirstRequest,
	);

	let ReportDtoUri = responseDataFirstRequest.ReportDto.URI
	let DocumentName = responseDataFirstRequest.ReportDto.DocumentName

	const optionsSecondRequest = {
			method: 'GET',
			uri: ReportDtoUri,
			json: false,
			encoding: null
		} satisfies IRequestOptions;

		const pdfBuffer = await this.helpers.requestWithAuthentication.call(
		this,
		'mfrApi',
		optionsSecondRequest,
	);

			const newItem: INodeExecutionData = {
						json: items[i].json,
						binary: {},
						pairedItem: { item: i },
					};

					if (items[i].binary !== undefined) {
						// Create a shallow copy of the binary data so that the old
						// data references which do not get changed still stay behind
						// but the incoming data does not get changed.
						Object.assign(newItem.binary!, items[i].binary);
					}

					items[i] = newItem;

					items[i].binary!['file'] = await this.helpers.prepareBinaryData.call(
       		 this,
       		 pdfBuffer, // raw Buffer
       		 DocumentName, // original filename
      	)

}}

// end

if(resource === 'report' && operation === 'generateReportFromReportDefinition'){
		// For file downloads the files get attached to the existing items
			return [items];
}

else{
	const executionData = this.helpers.constructExecutionMetaData(
		this.helpers.returnJsonArray(responseData as IDataObject[]),
		{ itemData: { item: i } },
	);
	returnData.push(...executionData);
}

```

## Share the output returned by the last node

The binary data only containing 1 file:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/6/a/6ad5fdabe4f8a9e9402d7206903d4612048f9d6b.png)

The json data having the correct number of items and link:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/6/6/66ac95033d61f2447fd94b7ac1136a3f2a055e72.png)

I want the binary data to be returned like this (supports multiple files):

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/2/4/248c6bc42b602252b1fee81be6bbb2b79a8ef1a7.jpeg)

Appreciate your help in advance!

Thank you,  
Alex

## Information on your n8n setup

- **n8n version: 1.89.2**
- **Database (default: SQLite): local deployment**
- **n8n EXECUTIONS\_PROCESS setting (default: own, main): local deployment**
- **Running n8n via (Docker, npm, n8n cloud, desktop app): `pnpm`**
- **Operating system: MAC**

---

<div class="post-metadata">

**Author:** ![alexnemes](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@alexnemes](https://community.n8n.io/u/alexnemes)\
**Post date:** [May 20, 2025, 2:26pm UTC](https://community.n8n.io/t/how-to-return-binary-data-in-custom-node/118067/2 "2025-05-20T14:26:36Z")

</div>

The issue is this part:

if(resource === ‘report’ && operation === ‘generateReportFromReportDefinition’){  
// For file downloads the files get attached to the existing items  
return [items];  
}

it returns just 1 item. How can I adapt it?

---

<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:** [August 18, 2025, 2:26pm UTC](https://community.n8n.io/t/how-to-return-binary-data-in-custom-node/118067/3 "2025-08-18T14:26:51Z")

</div>

Closed on August 18, 2025, 2:26pm UTC

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