mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-17 21:49:36 +02:00
Co-authored-by: Matsu <matias.huhta@n8n.io> Co-authored-by: Bernhard Wittmann <bernhard.wittmann@n8n.io> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: Elias Meire <elias@meire.dev> Co-authored-by: n8n-assistant[bot] <n8n-assistant[bot]@users.noreply.github.com> Co-authored-by: João Almeida <jg.almeida56@gmail.com> Co-authored-by: Savelii <savelii.sychov@n8n.io> Co-authored-by: Rick Gale <richardgale90@gmail.com> Co-authored-by: Emilia <100027345+sovietspaceship@users.noreply.github.com> Co-authored-by: oleg <me@olegivaniv.com> Co-authored-by: RomanDavydchuk <roman.davydchuk@n8n.io> Co-authored-by: Stephen Wright <sjw948@gmail.com> Co-authored-by: Yuliia Pominchuk <31064937+yuliia-pominchuk@users.noreply.github.com> Co-authored-by: Shireen Missi <94372015+ShireenMissi@users.noreply.github.com> Co-authored-by: Miguel Ángel Moreno <1411774+miguelsaddress@users.noreply.github.com> Co-authored-by: Anne Aguirre <anne.aguirre@n8n.io> Co-authored-by: Dimitri Lavrenük <20122620+dlavrenuek@users.noreply.github.com> Co-authored-by: Kai <kai.hartlage@n8n.io> Co-authored-by: Luigi Gubello <27034386+luigigubello@users.noreply.github.com> Co-authored-by: Danny Martini <danny@n8n.io> Co-authored-by: MHMD <45968454+dou-mhmd@users.noreply.github.com> Co-authored-by: Mutasem Aldmour <4711238+mutdmour@users.noreply.github.com> Co-authored-by: Iván Ovejero <ivov.src@gmail.com> Co-authored-by: Charlie Kolb <charlie@n8n.io>
70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
import {
|
|
NodeConnectionTypes,
|
|
type IExecuteFunctions,
|
|
type INodeExecutionData,
|
|
type INodeType,
|
|
type INodeTypeDescription,
|
|
} from 'n8n-workflow';
|
|
|
|
import { globWithDeadline } from '../Files/ReadWriteFile/helpers/utils';
|
|
import { generatePairedItemData } from '../../utils/utilities';
|
|
|
|
export class ReadBinaryFiles implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
hidden: true,
|
|
displayName: 'Read Binary Files',
|
|
name: 'readBinaryFiles',
|
|
icon: 'fa:file-import',
|
|
group: ['input'],
|
|
version: 1,
|
|
description: 'Reads binary files from disk',
|
|
defaults: {
|
|
name: 'Read Binary Files',
|
|
color: '#44AA44',
|
|
},
|
|
inputs: [NodeConnectionTypes.Main],
|
|
outputs: [NodeConnectionTypes.Main],
|
|
properties: [
|
|
{
|
|
displayName: 'File Selector',
|
|
name: 'fileSelector',
|
|
type: 'string',
|
|
default: '',
|
|
required: true,
|
|
placeholder: '*.jpg',
|
|
description: 'Pattern for files to read',
|
|
},
|
|
{
|
|
displayName: 'Property Name',
|
|
name: 'dataPropertyName',
|
|
type: 'string',
|
|
default: 'data',
|
|
required: true,
|
|
description: 'Name of the binary property to which to write the data of the read files',
|
|
},
|
|
],
|
|
};
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
const fileSelector = this.getNodeParameter('fileSelector', 0) as string;
|
|
const dataPropertyName = this.getNodeParameter('dataPropertyName', 0);
|
|
const pairedItem = generatePairedItemData(this.getInputData().length);
|
|
|
|
const files = await globWithDeadline(this.getNode(), fileSelector);
|
|
|
|
const items: INodeExecutionData[] = [];
|
|
for (const filePath of files) {
|
|
const stream = await this.helpers.createReadStream(await this.helpers.resolvePath(filePath));
|
|
items.push({
|
|
binary: {
|
|
[dataPropertyName]: await this.helpers.prepareBinaryData(stream, filePath),
|
|
},
|
|
json: {},
|
|
pairedItem,
|
|
});
|
|
}
|
|
|
|
return [items];
|
|
}
|
|
}
|