feat(core): Improvements/overhaul for nodes working with binary data (#7651)
Github issue / Community forum post (link here to close automatically): --------- Co-authored-by: Giulio Andreini <andreini@netseven.it> Co-authored-by: Marcus <marcus@n8n.io>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.convertToFile",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Core Nodes"],
|
||||
"resources": {
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.converttofile/"
|
||||
}
|
||||
]
|
||||
},
|
||||
"alias": [
|
||||
"CSV",
|
||||
"Spreadsheet",
|
||||
"Excel",
|
||||
"xls",
|
||||
"xlsx",
|
||||
"ods",
|
||||
"tabular",
|
||||
"encode",
|
||||
"encoding",
|
||||
"Move Binary Data",
|
||||
"Binary",
|
||||
"File",
|
||||
"JSON",
|
||||
"HTML",
|
||||
"ICS",
|
||||
"RTF",
|
||||
"64"
|
||||
],
|
||||
"subcategories": {
|
||||
"Core Nodes": ["Files", "Data Transformation"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import * as spreadsheet from './actions/spreadsheet.operation';
|
||||
import * as toBinary from './actions/toBinary.operation';
|
||||
import * as toJson from './actions/toJson.operation';
|
||||
import * as iCall from './actions/iCall.operation';
|
||||
|
||||
export class ConvertToFile implements INodeType {
|
||||
// eslint-disable-next-line n8n-nodes-base/node-class-description-missing-subtitle
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Convert to File',
|
||||
name: 'convertToFile',
|
||||
icon: 'file:convertToFile.svg',
|
||||
group: ['input'],
|
||||
version: 1,
|
||||
description: 'Convert JSON data to binary data',
|
||||
defaults: {
|
||||
name: 'Convert to File',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Convert to CSV',
|
||||
value: 'csv',
|
||||
action: 'Convert to CSV',
|
||||
description: 'Transform input data into a CSV file',
|
||||
},
|
||||
{
|
||||
name: 'Convert to HTML',
|
||||
value: 'html',
|
||||
action: 'Convert to HTML',
|
||||
description: 'Transform input data into a table in an HTML file',
|
||||
},
|
||||
{
|
||||
name: 'Convert to iCal',
|
||||
value: 'iCal',
|
||||
action: 'Convert to iCal',
|
||||
description: 'Converts each input item to an ICS event file',
|
||||
},
|
||||
{
|
||||
name: 'Convert to JSON',
|
||||
value: 'toJson',
|
||||
action: 'Convert to JSON',
|
||||
description: 'Transform input data into a single or multiple JSON files',
|
||||
},
|
||||
{
|
||||
name: 'Convert to ODS',
|
||||
value: 'ods',
|
||||
action: 'Convert to ODS',
|
||||
description: 'Transform input data into an ODS file',
|
||||
},
|
||||
{
|
||||
name: 'Convert to RTF',
|
||||
value: 'rtf',
|
||||
action: 'Convert to RTF',
|
||||
description: 'Transform input data into a table in an RTF file',
|
||||
},
|
||||
{
|
||||
name: 'Convert to XLS',
|
||||
value: 'xls',
|
||||
action: 'Convert to XLS',
|
||||
description: 'Transform input data into an Excel file',
|
||||
},
|
||||
{
|
||||
name: 'Convert to XLSX',
|
||||
value: 'xlsx',
|
||||
action: 'Convert to XLSX',
|
||||
description: 'Transform input data into an Excel file',
|
||||
},
|
||||
{
|
||||
name: 'Move Base64 String to File',
|
||||
value: 'toBinary',
|
||||
action: 'Move base64 string to file',
|
||||
description: 'Convert a base64-encoded string into its original file format',
|
||||
},
|
||||
],
|
||||
default: 'csv',
|
||||
},
|
||||
...spreadsheet.description,
|
||||
...toBinary.description,
|
||||
...toJson.description,
|
||||
...iCall.description,
|
||||
],
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions) {
|
||||
const items = this.getInputData();
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
let returnData: INodeExecutionData[] = [];
|
||||
|
||||
if (spreadsheet.operations.includes(operation)) {
|
||||
returnData = await spreadsheet.execute.call(this, items, operation);
|
||||
}
|
||||
|
||||
if (operation === 'toJson') {
|
||||
returnData = await toJson.execute.call(this, items);
|
||||
}
|
||||
|
||||
if (operation === 'toBinary') {
|
||||
returnData = await toBinary.execute.call(this, items);
|
||||
}
|
||||
|
||||
if (operation === 'iCal') {
|
||||
returnData = await iCall.execute.call(this, items);
|
||||
}
|
||||
|
||||
return [returnData];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import * as createEvent from '../../../ICalendar/createEvent.operation';
|
||||
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
export const description: INodeProperties[] = updateDisplayOptions(
|
||||
{
|
||||
show: {
|
||||
operation: ['iCal'],
|
||||
},
|
||||
},
|
||||
createEvent.description,
|
||||
);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, items: INodeExecutionData[]) {
|
||||
const returnData = await createEvent.execute.call(this, items);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import {
|
||||
NodeOperationError,
|
||||
type IExecuteFunctions,
|
||||
type INodeExecutionData,
|
||||
type INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { generatePairedItemData, updateDisplayOptions } from '@utils/utilities';
|
||||
import type { JsonToSpreadsheetBinaryOptions, JsonToSpreadsheetBinaryFormat } from '@utils/binary';
|
||||
|
||||
import { convertJsonToSpreadsheetBinary } from '@utils/binary';
|
||||
|
||||
export const operations = ['csv', 'html', 'rtf', 'ods', 'xls', 'xlsx'];
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Put Output File in Field',
|
||||
name: 'binaryPropertyName',
|
||||
type: 'string',
|
||||
default: 'data',
|
||||
required: true,
|
||||
placeholder: 'e.g data',
|
||||
hint: 'The name of the output binary field to put the file in',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Compression',
|
||||
name: 'compression',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'/operation': ['xlsx', 'ods'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to reduce the output file size',
|
||||
},
|
||||
{
|
||||
displayName: 'File Name',
|
||||
name: 'fileName',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Name of the output file',
|
||||
},
|
||||
{
|
||||
displayName: 'Header Row',
|
||||
name: 'headerRow',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Whether the first row of the file contains the header names',
|
||||
},
|
||||
{
|
||||
displayName: 'Sheet Name',
|
||||
name: 'sheetName',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'/operation': ['ods', 'xls', 'xlsx'],
|
||||
},
|
||||
},
|
||||
default: 'Sheet',
|
||||
description: 'Name of the sheet to create in the spreadsheet',
|
||||
placeholder: 'e.g. mySheet',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
operation: operations,
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
items: INodeExecutionData[],
|
||||
operation: string,
|
||||
) {
|
||||
let returnData: INodeExecutionData[] = [];
|
||||
|
||||
const pairedItem = generatePairedItemData(items.length);
|
||||
try {
|
||||
const options = this.getNodeParameter('options', 0, {}) as JsonToSpreadsheetBinaryOptions;
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0, 'data');
|
||||
|
||||
const binaryData = await convertJsonToSpreadsheetBinary.call(
|
||||
this,
|
||||
items,
|
||||
operation as JsonToSpreadsheetBinaryFormat,
|
||||
options,
|
||||
'File',
|
||||
);
|
||||
|
||||
const newItem: INodeExecutionData = {
|
||||
json: {},
|
||||
binary: {
|
||||
[binaryPropertyName]: binaryData,
|
||||
},
|
||||
pairedItem,
|
||||
};
|
||||
|
||||
returnData = [newItem];
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({
|
||||
json: {
|
||||
error: error.message,
|
||||
},
|
||||
pairedItem,
|
||||
});
|
||||
} else {
|
||||
throw new NodeOperationError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
import type { IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import type { JsonToBinaryOptions } from '@utils/binary';
|
||||
import { createBinaryFromJson } from '@utils/binary';
|
||||
import { encodeDecodeOptions } from '@utils/descriptions';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Base64 Input Field',
|
||||
name: 'sourceProperty',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
placeholder: 'e.g data',
|
||||
requiresDataPath: 'single',
|
||||
description:
|
||||
"The name of the input field that contains the base64 string to convert to a file. Use dot-notation for deep fields (e.g. 'level1.level2.currentKey').",
|
||||
},
|
||||
{
|
||||
displayName: 'Put Output File in Field',
|
||||
name: 'binaryPropertyName',
|
||||
type: 'string',
|
||||
default: 'data',
|
||||
required: true,
|
||||
placeholder: 'e.g data',
|
||||
hint: 'The name of the output binary field to put the file in',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Add Byte Order Mark (BOM)',
|
||||
description:
|
||||
'Whether to add special marker at the start of your text file. This marker helps some programs understand how to read the file correctly.',
|
||||
name: 'addBOM',
|
||||
displayOptions: {
|
||||
show: {
|
||||
encoding: ['utf8', 'cesu8', 'ucs2'],
|
||||
},
|
||||
},
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
displayName: 'Data Is Base64',
|
||||
name: 'dataIsBase64',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: 'Whether the data is already base64 encoded',
|
||||
},
|
||||
{
|
||||
displayName: 'Encoding',
|
||||
name: 'encoding',
|
||||
type: 'options',
|
||||
options: encodeDecodeOptions,
|
||||
default: 'utf8',
|
||||
description: 'Choose the character set to use to encode the data',
|
||||
displayOptions: {
|
||||
hide: {
|
||||
dataIsBase64: [true],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'File Name',
|
||||
name: 'fileName',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. myFile',
|
||||
description: 'Name of the output file',
|
||||
},
|
||||
{
|
||||
displayName: 'MIME Type',
|
||||
name: 'mimeType',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g text/plain',
|
||||
description:
|
||||
'The MIME type of the output file. <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types" target="_blank">Common MIME types</a>.',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
operation: ['toBinary'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, items: INodeExecutionData[]) {
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
const options = this.getNodeParameter('options', i, {});
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i, 'data');
|
||||
const sourceProperty = this.getNodeParameter('sourceProperty', i) as string;
|
||||
|
||||
const jsonToBinaryOptions: JsonToBinaryOptions = {
|
||||
sourceKey: sourceProperty,
|
||||
fileName: options.fileName as string,
|
||||
mimeType: options.mimeType as string,
|
||||
dataIsBase64: options.dataIsBase64 !== false,
|
||||
encoding: options.encoding as string,
|
||||
addBOM: options.addBOM as boolean,
|
||||
itemIndex: i,
|
||||
};
|
||||
|
||||
const binaryData = await createBinaryFromJson.call(this, items[i].json, jsonToBinaryOptions);
|
||||
|
||||
const newItem: INodeExecutionData = {
|
||||
json: {},
|
||||
binary: {
|
||||
[binaryPropertyName]: binaryData,
|
||||
},
|
||||
pairedItem: { item: i },
|
||||
};
|
||||
|
||||
returnData.push(newItem);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({
|
||||
json: {
|
||||
error: error.message,
|
||||
},
|
||||
pairedItem: {
|
||||
item: i,
|
||||
},
|
||||
});
|
||||
continue;
|
||||
}
|
||||
throw new NodeOperationError(this.getNode(), error, { itemIndex: i });
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
import type { IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { generatePairedItemData, updateDisplayOptions } from '@utils/utilities';
|
||||
import { createBinaryFromJson } from '@utils/binary';
|
||||
import { encodeDecodeOptions } from '@utils/descriptions';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Mode',
|
||||
name: 'mode',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'All Items to One File',
|
||||
value: 'once',
|
||||
},
|
||||
{
|
||||
name: 'Each Item to Separate File',
|
||||
value: 'each',
|
||||
},
|
||||
],
|
||||
default: 'once',
|
||||
},
|
||||
{
|
||||
displayName: 'Put Output File in Field',
|
||||
name: 'binaryPropertyName',
|
||||
type: 'string',
|
||||
default: 'data',
|
||||
required: true,
|
||||
placeholder: 'e.g data',
|
||||
hint: 'The name of the output binary field to put the file in',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Add Byte Order Mark (BOM)',
|
||||
name: 'addBOM',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
'Whether to add special marker at the start of your text file. This marker helps some programs understand how to read the file correctly.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
encoding: ['utf8', 'cesu8', 'ucs2'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Encoding',
|
||||
name: 'encoding',
|
||||
type: 'options',
|
||||
options: encodeDecodeOptions,
|
||||
default: 'utf8',
|
||||
description: 'Choose the character set to use to encode the data',
|
||||
},
|
||||
{
|
||||
displayName: 'File Name',
|
||||
name: 'fileName',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. myFile.json',
|
||||
description: 'Name of the output file',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
operation: ['toJson'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, items: INodeExecutionData[]) {
|
||||
let returnData: INodeExecutionData[] = [];
|
||||
|
||||
const mode = this.getNodeParameter('mode', 0, 'once') as string;
|
||||
if (mode === 'once') {
|
||||
const pairedItem = generatePairedItemData(items.length);
|
||||
try {
|
||||
const options = this.getNodeParameter('options', 0, {});
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0, 'data');
|
||||
|
||||
const binaryData = await createBinaryFromJson.call(
|
||||
this,
|
||||
items.map((item) => item.json),
|
||||
{
|
||||
fileName: options.fileName as string,
|
||||
mimeType: 'application/json',
|
||||
encoding: options.encoding as string,
|
||||
addBOM: options.addBOM as boolean,
|
||||
},
|
||||
);
|
||||
|
||||
const newItem: INodeExecutionData = {
|
||||
json: {},
|
||||
binary: {
|
||||
[binaryPropertyName]: binaryData,
|
||||
},
|
||||
pairedItem,
|
||||
};
|
||||
|
||||
returnData = [newItem];
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({
|
||||
json: {
|
||||
error: error.message,
|
||||
},
|
||||
pairedItem,
|
||||
});
|
||||
}
|
||||
throw new NodeOperationError(this.getNode(), error);
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
const options = this.getNodeParameter('options', i, {});
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i, 'data');
|
||||
|
||||
const binaryData = await createBinaryFromJson.call(this, items[i].json, {
|
||||
fileName: options.fileName as string,
|
||||
encoding: options.encoding as string,
|
||||
addBOM: options.addBOM as boolean,
|
||||
mimeType: 'application/json',
|
||||
itemIndex: i,
|
||||
});
|
||||
|
||||
const newItem: INodeExecutionData = {
|
||||
json: {},
|
||||
binary: {
|
||||
[binaryPropertyName]: binaryData,
|
||||
},
|
||||
pairedItem: { item: i },
|
||||
};
|
||||
|
||||
returnData.push(newItem);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({
|
||||
json: {
|
||||
error: error.message,
|
||||
},
|
||||
pairedItem: {
|
||||
item: i,
|
||||
},
|
||||
});
|
||||
continue;
|
||||
}
|
||||
throw new NodeOperationError(this.getNode(), error, { itemIndex: i });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g clip-path="url(#clip0_1147_463)">
|
||||
<path d="M170 39.8081C170 33.2867 175.287 28 181.808 28H338.41V189.59C338.41 196.218 343.782 201.59 350.41 201.59H512L512 472.893C512 479.415 506.713 484.701 500.192 484.701H181.808C177.972 484.701 174.564 482.873 172.407 480.039C175.619 477.958 178.665 475.515 181.488 472.708L271.488 383.208C282.057 372.697 288 358.406 288 343.5C288 328.594 282.057 314.303 271.488 303.792L181.488 214.292C177.969 210.793 174.103 207.858 170 205.487V39.8081Z" fill="#2244FF"/>
|
||||
<path d="M369.898 34C369.898 30.6863 372.584 28 375.898 28H378.564C381.7 28 384.708 29.2479 386.923 31.4684L508.551 153.386C510.76 155.6 512 158.599 512 161.726L512 164.102C512 167.416 509.314 170.102 506 170.102H375.898C372.584 170.102 369.898 167.416 369.898 164.102V34Z" fill="#2244FF"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M125.077 415.982C115.678 425.329 115.636 440.525 124.982 449.923C134.329 459.322 149.525 459.364 158.923 450.018L248.923 360.518C253.453 356.013 256 349.888 256 343.5C256 337.112 253.453 330.987 248.923 326.482L158.923 236.982C149.525 227.636 134.329 227.678 124.982 237.077C115.636 246.475 115.678 261.671 125.077 271.018L173.327 319L12 319C5.37257 319 -4.12516e-06 324.373 -4.41485e-06 331L-5.46392e-06 355C-5.75362e-06 361.627 5.37258 367 12 367L174.333 367L125.077 415.982Z" fill="#2244FF"/>
|
||||
</g>
|
||||
<defs>
|
||||
<clipPath id="clip0_1147_463">
|
||||
<rect width="512" height="512" fill="white"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.extractFromFile",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Core Nodes"],
|
||||
"resources": {
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.extractfromfile/"
|
||||
}
|
||||
]
|
||||
},
|
||||
"alias": [
|
||||
"CSV",
|
||||
"Spreadsheet",
|
||||
"Excel",
|
||||
"xls",
|
||||
"xlsx",
|
||||
"ods",
|
||||
"tabular",
|
||||
"decode",
|
||||
"decoding",
|
||||
"Move Binary Data",
|
||||
"Binary",
|
||||
"File",
|
||||
"PDF",
|
||||
"JSON",
|
||||
"HTML",
|
||||
"ICS",
|
||||
"txt",
|
||||
"Text",
|
||||
"RTF",
|
||||
"XML",
|
||||
"64"
|
||||
],
|
||||
"subcategories": {
|
||||
"Core Nodes": ["Files", "Data Transformation"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import * as spreadsheet from './actions/spreadsheet.operation';
|
||||
import * as moveTo from './actions/moveTo.operation';
|
||||
import * as pdf from './actions/pdf.operation';
|
||||
|
||||
export class ExtractFromFile implements INodeType {
|
||||
// eslint-disable-next-line n8n-nodes-base/node-class-description-missing-subtitle
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Extract From File',
|
||||
name: 'extractFromFile',
|
||||
icon: 'file:extractFromFile.svg',
|
||||
group: ['input'],
|
||||
version: 1,
|
||||
description: 'Convert binary data to JSON',
|
||||
defaults: {
|
||||
name: 'Extract From File',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-options-type-unsorted-items
|
||||
options: [
|
||||
{
|
||||
name: 'Extract From CSV',
|
||||
value: 'csv',
|
||||
action: 'Extract from CSV',
|
||||
description: 'Transform a CSV file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Extract From HTML',
|
||||
value: 'html',
|
||||
action: 'Extract from HTML',
|
||||
description: 'Transform a table in an HTML file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Extract From JSON',
|
||||
value: 'fromJson',
|
||||
action: 'Extract from JSON',
|
||||
description: 'Transform a JSON file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Extract From ICS',
|
||||
value: 'fromIcs',
|
||||
action: 'Extract from ICS',
|
||||
description: 'Transform a ICS file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Extract From ODS',
|
||||
value: 'ods',
|
||||
action: 'Extract from ODS',
|
||||
description: 'Transform an ODS file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Extract From PDF',
|
||||
value: 'pdf',
|
||||
action: 'Extract from PDF',
|
||||
description: 'Extracts the content and metadata from a PDF file',
|
||||
},
|
||||
{
|
||||
name: 'Extract From RTF',
|
||||
value: 'rtf',
|
||||
action: 'Extract from RTF',
|
||||
description: 'Transform a table in an RTF file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Extract From Text File',
|
||||
value: 'text',
|
||||
action: 'Extract from text file',
|
||||
description: 'Extracts the content of a text file',
|
||||
},
|
||||
{
|
||||
name: 'Extract From XML',
|
||||
value: 'xml',
|
||||
action: 'Extract from XLS',
|
||||
description: 'Extracts the content of an XML file',
|
||||
},
|
||||
{
|
||||
name: 'Extract From XLS',
|
||||
value: 'xls',
|
||||
action: 'Extract from XLS',
|
||||
description: 'Transform an Excel file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Extract From XLSX',
|
||||
value: 'xlsx',
|
||||
action: 'Extract from XLSX',
|
||||
description: 'Transform an Excel file into output items',
|
||||
},
|
||||
{
|
||||
name: 'Move File to Base64 String',
|
||||
value: 'binaryToPropery',
|
||||
action: 'Move file to base64 string',
|
||||
description: 'Convert a file into a base64-encoded string',
|
||||
},
|
||||
],
|
||||
default: 'csv',
|
||||
},
|
||||
...spreadsheet.description,
|
||||
...moveTo.description,
|
||||
...pdf.description,
|
||||
],
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions) {
|
||||
const items = this.getInputData();
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
let returnData: INodeExecutionData[] = [];
|
||||
|
||||
if (spreadsheet.operations.includes(operation)) {
|
||||
returnData = await spreadsheet.execute.call(this, items, 'operation');
|
||||
}
|
||||
|
||||
if (['binaryToPropery', 'fromJson', 'text', 'fromIcs', 'xml'].includes(operation)) {
|
||||
returnData = await moveTo.execute.call(this, items, operation);
|
||||
}
|
||||
|
||||
if (operation === 'pdf') {
|
||||
returnData = await pdf.execute.call(this, items);
|
||||
}
|
||||
|
||||
return [returnData];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { BINARY_ENCODING, NodeOperationError, deepCopy, jsonParse } from 'n8n-workflow';
|
||||
|
||||
import { encodeDecodeOptions } from '@utils/descriptions';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
import get from 'lodash/get';
|
||||
import set from 'lodash/set';
|
||||
import unset from 'lodash/unset';
|
||||
|
||||
import iconv from 'iconv-lite';
|
||||
|
||||
import { icsCalendarToObject } from 'ts-ics';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Input Binary Field',
|
||||
name: 'binaryPropertyName',
|
||||
type: 'string',
|
||||
default: 'data',
|
||||
required: true,
|
||||
placeholder: 'e.g data',
|
||||
hint: 'The name of the input field containing the file data to be processed',
|
||||
},
|
||||
{
|
||||
displayName: 'Destination Output Field',
|
||||
name: 'destinationKey',
|
||||
type: 'string',
|
||||
default: 'data',
|
||||
required: true,
|
||||
placeholder: 'e.g data',
|
||||
description: 'The name of the output field that will contain the extracted data',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'File Encoding',
|
||||
name: 'encoding',
|
||||
type: 'options',
|
||||
options: encodeDecodeOptions,
|
||||
default: 'utf8',
|
||||
description: 'Specify the encoding of the file, defaults to UTF-8',
|
||||
},
|
||||
{
|
||||
displayName: 'Strip BOM',
|
||||
name: 'stripBOM',
|
||||
displayOptions: {
|
||||
show: {
|
||||
encoding: ['utf8', 'cesu8', 'ucs2'],
|
||||
},
|
||||
},
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description:
|
||||
'Whether to strip the BOM (Byte Order Mark) from the file, this could help in an environment where the presence of the BOM is causing issues or inconsistencies',
|
||||
},
|
||||
{
|
||||
displayName: 'Keep Source',
|
||||
name: 'keepSource',
|
||||
type: 'options',
|
||||
default: 'json',
|
||||
options: [
|
||||
{
|
||||
name: 'JSON',
|
||||
value: 'json',
|
||||
description: 'Include JSON data of the input item',
|
||||
},
|
||||
{
|
||||
name: 'Binary',
|
||||
value: 'binary',
|
||||
description: 'Include binary data of the input item',
|
||||
},
|
||||
{
|
||||
name: 'Both',
|
||||
value: 'both',
|
||||
description: 'Include both JSON and binary data of the input item',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
operation: ['binaryToPropery', 'fromJson', 'text', 'fromIcs', 'xml'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
items: INodeExecutionData[],
|
||||
operation: string,
|
||||
) {
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||
try {
|
||||
const item = items[itemIndex];
|
||||
const options = this.getNodeParameter('options', itemIndex);
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex);
|
||||
|
||||
const newItem: INodeExecutionData = {
|
||||
json: {},
|
||||
pairedItem: { item: itemIndex },
|
||||
};
|
||||
|
||||
const value = get(item.binary, binaryPropertyName);
|
||||
|
||||
if (!value) continue;
|
||||
|
||||
const encoding = (options.encoding as string) || 'utf8';
|
||||
const buffer = await this.helpers.getBinaryDataBuffer(itemIndex, binaryPropertyName);
|
||||
|
||||
if (options.keepSource && options.keepSource !== 'binary') {
|
||||
newItem.json = deepCopy(item.json);
|
||||
}
|
||||
|
||||
let convertedValue: string | IDataObject;
|
||||
if (operation !== 'binaryToPropery') {
|
||||
convertedValue = iconv.decode(buffer, encoding, {
|
||||
stripBOM: options.stripBOM as boolean,
|
||||
});
|
||||
} else {
|
||||
convertedValue = Buffer.from(buffer).toString(BINARY_ENCODING);
|
||||
}
|
||||
|
||||
if (operation === 'fromJson') {
|
||||
if (convertedValue === '') {
|
||||
convertedValue = {};
|
||||
} else {
|
||||
convertedValue = jsonParse(convertedValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (operation === 'fromIcs') {
|
||||
convertedValue = icsCalendarToObject(convertedValue as string);
|
||||
}
|
||||
|
||||
const destinationKey = this.getNodeParameter('destinationKey', itemIndex, '') as string;
|
||||
set(newItem.json, destinationKey, convertedValue);
|
||||
|
||||
if (options.keepSource === 'binary' || options.keepSource === 'both') {
|
||||
newItem.binary = item.binary;
|
||||
} else {
|
||||
// this binary data would not be included, but there also might be other binary data
|
||||
// which should be included, copy it over and unset current binary data
|
||||
newItem.binary = deepCopy(item.binary);
|
||||
unset(newItem.binary, binaryPropertyName);
|
||||
}
|
||||
|
||||
returnData.push(newItem);
|
||||
} catch (error) {
|
||||
let errorDescription;
|
||||
if (error.message.includes('Unexpected token')) {
|
||||
error.message = "The file selected in 'Input Binary Field' is not in JSON format";
|
||||
errorDescription =
|
||||
"Try to change the operation or select a JSON file in 'Input Binary Field'";
|
||||
}
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({
|
||||
json: {
|
||||
error: error.message,
|
||||
},
|
||||
pairedItem: {
|
||||
item: itemIndex,
|
||||
},
|
||||
});
|
||||
continue;
|
||||
}
|
||||
throw new NodeOperationError(this.getNode(), error, {
|
||||
itemIndex,
|
||||
description: errorDescription,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
import type { IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import { NodeOperationError, deepCopy } from 'n8n-workflow';
|
||||
|
||||
import unset from 'lodash/unset';
|
||||
|
||||
import { extractDataFromPDF } from '@utils/binary';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Input Binary Field',
|
||||
name: 'binaryPropertyName',
|
||||
type: 'string',
|
||||
default: 'data',
|
||||
required: true,
|
||||
placeholder: 'e.g data',
|
||||
hint: 'The name of the input binary field containing the file to be extracted',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Join Pages',
|
||||
name: 'joinPages',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description:
|
||||
'Whether to join the text from all pages or return an array of text from each page',
|
||||
},
|
||||
{
|
||||
displayName: 'Keep Source',
|
||||
name: 'keepSource',
|
||||
type: 'options',
|
||||
default: 'json',
|
||||
options: [
|
||||
{
|
||||
name: 'JSON',
|
||||
value: 'json',
|
||||
description: 'Include JSON data of the input item',
|
||||
},
|
||||
{
|
||||
name: 'Binary',
|
||||
value: 'binary',
|
||||
description: 'Include binary data of the input item',
|
||||
},
|
||||
{
|
||||
name: 'Both',
|
||||
value: 'both',
|
||||
description: 'Include both JSON and binary data of the input item',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Max Pages',
|
||||
name: 'maxPages',
|
||||
type: 'number',
|
||||
default: 0,
|
||||
description: 'Maximum number of pages to include',
|
||||
},
|
||||
{
|
||||
displayName: 'Password',
|
||||
name: 'password',
|
||||
type: 'string',
|
||||
typeOptions: { password: true },
|
||||
default: '',
|
||||
description: 'Prowide password, if the PDF is encrypted',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
operation: ['pdf'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, items: INodeExecutionData[]) {
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||
try {
|
||||
const item = items[itemIndex];
|
||||
const options = this.getNodeParameter('options', itemIndex);
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex);
|
||||
|
||||
const json = await extractDataFromPDF.call(
|
||||
this,
|
||||
binaryPropertyName,
|
||||
options.password as string,
|
||||
options.maxPages as number,
|
||||
options.joinPages as boolean,
|
||||
itemIndex,
|
||||
);
|
||||
|
||||
const newItem: INodeExecutionData = {
|
||||
json: {},
|
||||
pairedItem: { item: itemIndex },
|
||||
};
|
||||
|
||||
if (options.keepSource && options.keepSource !== 'binary') {
|
||||
newItem.json = { ...deepCopy(item.json), ...json };
|
||||
} else {
|
||||
newItem.json = json;
|
||||
}
|
||||
|
||||
if (options.keepSource === 'binary' || options.keepSource === 'both') {
|
||||
newItem.binary = item.binary;
|
||||
} else {
|
||||
// this binary data would not be included, but there also might be other binary data
|
||||
// which should be included, copy it over and unset current binary data
|
||||
newItem.binary = deepCopy(item.binary);
|
||||
unset(newItem.binary, binaryPropertyName);
|
||||
}
|
||||
|
||||
returnData.push(newItem);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({
|
||||
json: {
|
||||
error: error.message,
|
||||
},
|
||||
pairedItem: {
|
||||
item: itemIndex,
|
||||
},
|
||||
});
|
||||
continue;
|
||||
}
|
||||
throw new NodeOperationError(this.getNode(), error, { itemIndex });
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import type { IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import * as fromFile from '../../../SpreadsheetFile/v2/fromFile.operation';
|
||||
|
||||
export const operations = ['csv', 'html', 'rtf', 'ods', 'xls', 'xlsx'];
|
||||
|
||||
export const description: INodeProperties[] = fromFile.description
|
||||
.filter((property) => property.name !== 'fileFormat')
|
||||
.map((property) => {
|
||||
const newProperty = { ...property };
|
||||
newProperty.displayOptions = {
|
||||
show: {
|
||||
operation: operations,
|
||||
},
|
||||
};
|
||||
|
||||
if (newProperty.name === 'options') {
|
||||
newProperty.options = (newProperty.options as INodeProperties[]).map((option) => {
|
||||
let newOption = option;
|
||||
if (['delimiter', 'fromLine', 'maxRowCount', 'enableBOM'].includes(option.name)) {
|
||||
newOption = { ...option, displayOptions: { show: { '/operation': ['csv'] } } };
|
||||
}
|
||||
if (option.name === 'sheetName') {
|
||||
newOption = {
|
||||
...option,
|
||||
displayOptions: { show: { '/operation': ['ods', 'xls', 'xlsx'] } },
|
||||
description: 'Name of the sheet to read from in the spreadsheet',
|
||||
};
|
||||
}
|
||||
if (option.name === 'range') {
|
||||
newOption = {
|
||||
...option,
|
||||
displayOptions: { show: { '/operation': ['ods', 'xls', 'xlsx'] } },
|
||||
};
|
||||
}
|
||||
if (['includeEmptyCells', 'headerRow'].includes(option.name)) {
|
||||
newOption = {
|
||||
...option,
|
||||
displayOptions: { show: { '/operation': ['ods', 'xls', 'xlsx', 'csv', 'html'] } },
|
||||
};
|
||||
}
|
||||
return newOption;
|
||||
});
|
||||
}
|
||||
return newProperty;
|
||||
});
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
items: INodeExecutionData[],
|
||||
fileFormatProperty: string,
|
||||
) {
|
||||
const returnData: INodeExecutionData[] = await fromFile.execute.call(
|
||||
this,
|
||||
items,
|
||||
fileFormatProperty,
|
||||
);
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M0 39.8158C0 33.2901 5.28667 28 11.8081 28H168.41V189.704C168.41 196.331 173.782 201.704 180.41 201.704H342L342 287H268C243.699 287 224 306.699 224 331V355C224 379.301 243.699 399 268 399L342 399L342 473.184C342 479.71 336.713 485 330.192 485H11.8081C5.28667 485 0 479.71 0 473.184V39.8158Z" fill="#003355"/>
|
||||
<path d="M199.898 34C199.898 30.6863 202.584 28 205.898 28H208.564C211.7 28 214.708 29.2487 216.923 31.4707L338.551 153.468C340.76 155.683 342 158.684 342 161.813L342 164.195C342 167.509 339.314 170.195 336 170.195H205.898C202.584 170.195 199.898 167.509 199.898 164.195V34Z" fill="#003355"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M381.077 415.982C371.678 425.329 371.636 440.525 380.982 449.923C390.329 459.322 405.525 459.364 414.923 450.018L504.923 360.518C509.453 356.013 512 349.888 512 343.5C512 337.112 509.453 330.987 504.923 326.482L414.923 236.982C405.525 227.636 390.329 227.678 380.982 237.077C371.636 246.475 371.678 261.671 381.077 271.018L429.327 319L268 319C261.373 319 256 324.373 256 331L256 355C256 361.627 261.373 367 268 367L430.333 367L381.077 415.982Z" fill="#003355"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.readWriteFile",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Core Nodes"],
|
||||
"resources": {
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.filesreadwrite/"
|
||||
}
|
||||
]
|
||||
},
|
||||
"alias": ["Binary", "File", "Text", "Open", "Import", "Save", "Export", "Disk", "Transfer"],
|
||||
"subcategories": {
|
||||
"Core Nodes": ["Files"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import * as read from './actions/read.operation';
|
||||
import * as write from './actions/write.operation';
|
||||
|
||||
export class ReadWriteFile implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Read/Write Files from Disk',
|
||||
name: 'readWriteFile',
|
||||
icon: 'file:readWriteFile.svg',
|
||||
group: ['input'],
|
||||
version: 1,
|
||||
description: 'Read or write files from the computer that runs n8n',
|
||||
defaults: {
|
||||
name: 'Read/Write Files from Disk',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
properties: [
|
||||
{
|
||||
displayName:
|
||||
'Use this node to read and write files on the same computer running n8n. To handle files between different computers please use other nodes (e.g. FTP, HTTP Request, AWS).',
|
||||
name: 'info',
|
||||
type: 'notice',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Read File(s) From Disk',
|
||||
value: 'read',
|
||||
description: 'Retrieve one or more files from the computer that runs n8n',
|
||||
action: 'Read File(s) From Disk',
|
||||
},
|
||||
{
|
||||
name: 'Write File to Disk',
|
||||
value: 'write',
|
||||
description: 'Create a binary file on the computer that runs n8n',
|
||||
action: 'Write File to Disk',
|
||||
},
|
||||
],
|
||||
default: 'read',
|
||||
},
|
||||
...read.description,
|
||||
...write.description,
|
||||
],
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions) {
|
||||
const operation = this.getNodeParameter('operation', 0, 'read');
|
||||
const items = this.getInputData();
|
||||
let returnData: INodeExecutionData[] = [];
|
||||
|
||||
if (operation === 'read') {
|
||||
returnData = await read.execute.call(this, items);
|
||||
}
|
||||
|
||||
if (operation === 'write') {
|
||||
returnData = await write.execute.call(this, items);
|
||||
}
|
||||
|
||||
return [returnData];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
import type { IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
||||
|
||||
import glob from 'fast-glob';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
import { errorMapper } from '../helpers/utils';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'File(s) Selector',
|
||||
name: 'fileSelector',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
placeholder: 'e.g. /home/user/Pictures/**/*.png',
|
||||
hint: 'Supports patterns, learn more <a href="https://github.com/micromatch/picomatch#basic-globbing" target="_blank">here</a>',
|
||||
description: "Specify a file's path or path pattern to read multiple files",
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'File Extension',
|
||||
name: 'fileExtension',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. zip',
|
||||
description: 'Extension of the file in the output binary',
|
||||
},
|
||||
{
|
||||
displayName: 'File Name',
|
||||
name: 'fileName',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. data.zip',
|
||||
description: 'Name of the file in the output binary',
|
||||
},
|
||||
{
|
||||
displayName: 'Mime Type',
|
||||
name: 'mimeType',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. application/zip',
|
||||
description: 'Mime type of the file in the output binary',
|
||||
},
|
||||
{
|
||||
displayName: 'Put Output File in Field',
|
||||
name: 'dataPropertyName',
|
||||
type: 'string',
|
||||
default: 'data',
|
||||
placeholder: 'e.g. data',
|
||||
description: "By default 'data' is used",
|
||||
hint: 'The name of the output binary field to put the file in',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
operation: ['read'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, items: INodeExecutionData[]) {
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
let fileSelector;
|
||||
|
||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||
try {
|
||||
fileSelector = this.getNodeParameter('fileSelector', itemIndex) as string;
|
||||
const options = this.getNodeParameter('options', itemIndex, {});
|
||||
|
||||
let dataPropertyName = 'data';
|
||||
|
||||
if (options.dataPropertyName) {
|
||||
dataPropertyName = options.dataPropertyName as string;
|
||||
}
|
||||
|
||||
const files = await glob(fileSelector);
|
||||
|
||||
const newItems: INodeExecutionData[] = [];
|
||||
for (const filePath of files) {
|
||||
const stream = await this.helpers.createReadStream(filePath);
|
||||
const binaryData = await this.helpers.prepareBinaryData(stream, filePath);
|
||||
|
||||
if (options.fileName !== undefined) {
|
||||
binaryData.fileName = options.fileName as string;
|
||||
}
|
||||
|
||||
if (options.fileExtension !== undefined) {
|
||||
binaryData.fileExtension = options.fileExtension as string;
|
||||
}
|
||||
|
||||
if (options.mimeType !== undefined) {
|
||||
binaryData.mimeType = options.mimeType as string;
|
||||
}
|
||||
|
||||
newItems.push({
|
||||
binary: {
|
||||
[dataPropertyName]: binaryData,
|
||||
},
|
||||
json: {
|
||||
mimeType: binaryData.mimeType,
|
||||
fileType: binaryData.fileType,
|
||||
fileName: binaryData.fileName,
|
||||
directory: binaryData.directory,
|
||||
fileExtension: binaryData.fileExtension,
|
||||
fileSize: binaryData.fileSize,
|
||||
},
|
||||
pairedItem: {
|
||||
item: itemIndex,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
returnData.push(...newItems);
|
||||
} catch (error) {
|
||||
const nodeOperatioinError = errorMapper.call(this, error, itemIndex, {
|
||||
filePath: fileSelector,
|
||||
operation: 'read',
|
||||
});
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({
|
||||
json: {
|
||||
error: nodeOperatioinError.message,
|
||||
},
|
||||
pairedItem: {
|
||||
item: itemIndex,
|
||||
},
|
||||
});
|
||||
continue;
|
||||
}
|
||||
throw nodeOperatioinError;
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
import type { IExecuteFunctions, INodeExecutionData, INodeProperties } from 'n8n-workflow';
|
||||
import { BINARY_ENCODING } from 'n8n-workflow';
|
||||
|
||||
import type { Readable } from 'stream';
|
||||
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
import { errorMapper } from '../helpers/utils';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'File Path and Name',
|
||||
name: 'fileName',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
placeholder: 'e.g. /data/example.jpg',
|
||||
description:
|
||||
'Path and name of the file that should be written. Also include the file extension.',
|
||||
},
|
||||
{
|
||||
displayName: 'Input Binary Field',
|
||||
name: 'dataPropertyName',
|
||||
type: 'string',
|
||||
default: 'data',
|
||||
placeholder: 'e.g. data',
|
||||
required: true,
|
||||
hint: 'The name of the input binary field containing the file to be written',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Append',
|
||||
name: 'append',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description:
|
||||
"Whether to append to an existing file. While it's commonly used with text files, it's not limited to them, however, it wouldn't be applicable for file types that have a specific structure like most binary formats.",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
operation: ['write'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, items: INodeExecutionData[]) {
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
let fileName;
|
||||
|
||||
let item: INodeExecutionData;
|
||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||
try {
|
||||
const dataPropertyName = this.getNodeParameter('dataPropertyName', itemIndex);
|
||||
fileName = this.getNodeParameter('fileName', itemIndex) as string;
|
||||
const options = this.getNodeParameter('options', itemIndex, {});
|
||||
const flag: string = options.append ? 'a' : 'w';
|
||||
|
||||
item = items[itemIndex];
|
||||
|
||||
const newItem: INodeExecutionData = {
|
||||
json: {},
|
||||
pairedItem: {
|
||||
item: itemIndex,
|
||||
},
|
||||
};
|
||||
Object.assign(newItem.json, item.json);
|
||||
|
||||
const binaryData = this.helpers.assertBinaryData(itemIndex, dataPropertyName);
|
||||
|
||||
let fileContent: Buffer | Readable;
|
||||
if (binaryData.id) {
|
||||
fileContent = await this.helpers.getBinaryStream(binaryData.id);
|
||||
} else {
|
||||
fileContent = Buffer.from(binaryData.data, BINARY_ENCODING);
|
||||
}
|
||||
|
||||
// Write the file to disk
|
||||
await this.helpers.writeContentToFile(fileName, fileContent, flag);
|
||||
|
||||
if (item.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.
|
||||
newItem.binary = {};
|
||||
Object.assign(newItem.binary, item.binary);
|
||||
}
|
||||
|
||||
// Add the file name to data
|
||||
newItem.json.fileName = fileName;
|
||||
|
||||
returnData.push(newItem);
|
||||
} catch (error) {
|
||||
const nodeOperatioinError = errorMapper.call(this, error, itemIndex, {
|
||||
filePath: fileName,
|
||||
operation: 'write',
|
||||
});
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({
|
||||
json: {
|
||||
error: nodeOperatioinError.message,
|
||||
},
|
||||
pairedItem: {
|
||||
item: itemIndex,
|
||||
},
|
||||
});
|
||||
continue;
|
||||
}
|
||||
throw nodeOperatioinError;
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import type { IDataObject, IExecuteFunctions } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
export function errorMapper(
|
||||
this: IExecuteFunctions,
|
||||
error: Error,
|
||||
itemIndex: number,
|
||||
context?: IDataObject,
|
||||
) {
|
||||
let message;
|
||||
let description;
|
||||
|
||||
if (error.message.includes('Cannot create a string longer than')) {
|
||||
message = 'The file is too large';
|
||||
description =
|
||||
'The binary file you are attempting to read exceeds 512MB, which is limit when using default binary data mode, try using the filesystem binary mode. More information <a href="https://docs.n8n.io/hosting/scaling/binary-data/" target="_blank">here</a>.';
|
||||
} else if (error.message.includes('EACCES') && context?.operation === 'read') {
|
||||
const path =
|
||||
((error as unknown as IDataObject).path as string) || (context?.filePath as string);
|
||||
message = `You don't have the permissions to access ${path}`;
|
||||
description =
|
||||
"Verify that the path specified in 'File(s) Selector' is correct, or change the file(s) permissions if needed";
|
||||
} else if (error.message.includes('EACCES') && context?.operation === 'write') {
|
||||
const path =
|
||||
((error as unknown as IDataObject).path as string) || (context?.filePath as string);
|
||||
message = `You don't have the permissions to write the file ${path}`;
|
||||
description =
|
||||
"Specify another destination folder in 'File Path and Name', or change the permissions of the parent folder";
|
||||
}
|
||||
|
||||
return new NodeOperationError(this.getNode(), error, { itemIndex, message, description });
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g clip-path="url(#clip0_1141_1547)">
|
||||
<path d="M0 12C0 5.37258 5.37258 0 12 0H159V154C159 160.627 164.373 166 171 166H325V242H228.562C210.895 242 194.656 251.705 186.288 267.264L129.203 373.407C125.131 380.978 123 389.44 123 398.037V434H12C5.37257 434 0 428.627 0 422V12Z" fill="#44AA44"/>
|
||||
<path d="M325 134V127.401C325 124.223 323.74 121.175 321.495 118.925L206.369 3.52481C204.118 1.2682 201.061 0 197.873 0H191V134H325Z" fill="#44AA44"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M228.563 274C222.674 274 217.261 277.235 214.472 282.421L172.211 361H492.64L444.67 281.717C441.772 276.927 436.58 274 430.981 274H228.563Z" fill="#44AA44"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M155 409C155 400.163 162.163 393 171 393H496C504.837 393 512 400.163 512 409V496C512 504.837 504.837 512 496 512H171C162.163 512 155 504.837 155 496V409ZM397 453C397 466.255 386.255 477 373 477C359.745 477 349 466.255 349 453C349 439.745 359.745 429 373 429C386.255 429 397 439.745 397 453ZM445 477C458.255 477 469 466.255 469 453C469 439.745 458.255 429 445 429C431.745 429 421 439.745 421 453C421 466.255 431.745 477 445 477Z" fill="#44AA44"/>
|
||||
</g>
|
||||
<defs>
|
||||
<clipPath id="clip0_1141_1547">
|
||||
<rect width="512" height="512" fill="white"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,101 @@
|
||||
/* eslint-disable @typescript-eslint/no-loop-func */
|
||||
import * as Helpers from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
|
||||
describe('Test ReadWriteFile Node', () => {
|
||||
beforeEach(async () => {
|
||||
await Helpers.initBinaryDataService();
|
||||
});
|
||||
|
||||
const temporaryDir = Helpers.createTemporaryDir();
|
||||
const directory = __dirname.replace(/\\/gi, '/');
|
||||
|
||||
const workflow = Helpers.readJsonFileSync(
|
||||
'nodes/Files/ReadWriteFile/test/ReadWriteFile.workflow.json',
|
||||
);
|
||||
|
||||
const readFileNode = workflow.nodes.find((n: any) => n.name === 'Read from Disk');
|
||||
readFileNode.parameters.fileSelector = `${directory}/image.jpg`;
|
||||
|
||||
const writeFileNode = workflow.nodes.find((n: any) => n.name === 'Write to Disk');
|
||||
writeFileNode.parameters.fileName = `${temporaryDir}/image-written.jpg`;
|
||||
|
||||
const tests: WorkflowTestData[] = [
|
||||
{
|
||||
description: 'nodes/Files/ReadWriteFile/test/ReadWriteFile.workflow.json',
|
||||
input: {
|
||||
workflowData: workflow,
|
||||
},
|
||||
output: {
|
||||
nodeData: {
|
||||
'Read from Disk': [
|
||||
[
|
||||
{
|
||||
json: {
|
||||
directory,
|
||||
fileExtension: 'jpg',
|
||||
fileName: 'image.jpg',
|
||||
fileSize: '1.04 kB',
|
||||
fileType: 'image',
|
||||
mimeType: 'image/jpeg',
|
||||
},
|
||||
binary: {
|
||||
data: {
|
||||
mimeType: 'image/jpeg',
|
||||
fileType: 'image',
|
||||
fileExtension: 'jpg',
|
||||
data: '/9j/4AAQSkZJRgABAQEASABIAAD/4QBmRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAExAAIAAAAQAAAATgAAAAAAARlJAAAD6AABGUkAAAPocGFpbnQubmV0IDUuMC4xAP/bAEMAIBYYHBgUIBwaHCQiICYwUDQwLCwwYkZKOlB0Znp4cmZwboCQuJyAiK6KbnCg2qKuvsTO0M58muLy4MjwuMrOxv/bAEMBIiQkMCowXjQ0XsaEcITGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxv/AABEIAB8AOwMBEgACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/AOgqgrXF2zNHJ5aKcD3oNPZ23di/VKG82bkuTh1OMgdaAdOSLtZ6G5ut0iSeWoOAKAdO27NCqUN8oQrcHDqccDrQDpyRNPdRwEKcsx7CobIebPLORwThc0inGMF724jagNpxG4OOM1dIDAgjIPBpkqUOxnR2pmh85pW3nJB9KkNi4yqTssZ6rSNXNX0ehHFfusYDLuI7+tXY4I40ChQcdzQRKcL7Fb7PcQO32cqUY5we1XqZPtH11KsFoFDGYK7sckkZxVqgTnJlEQXMBZYGUoTkZ7VeoH7RvcqwWaIh80K7k5JIq1QJzkyhbMtvdSxMdqnlc1amgjmx5i5I70inNSVpFdrmaWRltkBVerHvUW57B2AUNGxyOaC+VW9xXLVrcGbcjrtkXqKZZxvveeTAL9APSgiooq1ty3RTMj//2Q==',
|
||||
directory,
|
||||
fileName: 'image.jpg',
|
||||
fileSize: '1.04 kB',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
'Write to Disk': [
|
||||
[
|
||||
{
|
||||
json: {
|
||||
directory,
|
||||
fileExtension: 'jpg',
|
||||
fileName: writeFileNode.parameters.fileName,
|
||||
fileSize: '1.04 kB',
|
||||
fileType: 'image',
|
||||
mimeType: 'image/jpeg',
|
||||
},
|
||||
binary: {
|
||||
data: {
|
||||
mimeType: 'image/jpeg',
|
||||
fileType: 'image',
|
||||
fileExtension: 'jpg',
|
||||
data: '/9j/4AAQSkZJRgABAQEASABIAAD/4QBmRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAExAAIAAAAQAAAATgAAAAAAARlJAAAD6AABGUkAAAPocGFpbnQubmV0IDUuMC4xAP/bAEMAIBYYHBgUIBwaHCQiICYwUDQwLCwwYkZKOlB0Znp4cmZwboCQuJyAiK6KbnCg2qKuvsTO0M58muLy4MjwuMrOxv/bAEMBIiQkMCowXjQ0XsaEcITGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxv/AABEIAB8AOwMBEgACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/AOgqgrXF2zNHJ5aKcD3oNPZ23di/VKG82bkuTh1OMgdaAdOSLtZ6G5ut0iSeWoOAKAdO27NCqUN8oQrcHDqccDrQDpyRNPdRwEKcsx7CobIebPLORwThc0inGMF724jagNpxG4OOM1dIDAgjIPBpkqUOxnR2pmh85pW3nJB9KkNi4yqTssZ6rSNXNX0ehHFfusYDLuI7+tXY4I40ChQcdzQRKcL7Fb7PcQO32cqUY5we1XqZPtH11KsFoFDGYK7sckkZxVqgTnJlEQXMBZYGUoTkZ7VeoH7RvcqwWaIh80K7k5JIq1QJzkyhbMtvdSxMdqnlc1amgjmx5i5I70inNSVpFdrmaWRltkBVerHvUW57B2AUNGxyOaC+VW9xXLVrcGbcjrtkXqKZZxvveeTAL9APSgiooq1ty3RTMj//2Q==',
|
||||
directory,
|
||||
fileName: 'image.jpg',
|
||||
fileSize: '1.04 kB',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const nodeTypes = Helpers.setup(tests);
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => {
|
||||
const { result } = await executeWorkflow(testData, nodeTypes);
|
||||
|
||||
const resultNodeData = Helpers.getResultNodeData(result, testData);
|
||||
resultNodeData.forEach(({ nodeName, resultData }) => {
|
||||
expect(resultData).toEqual(testData.output.nodeData[nodeName]);
|
||||
});
|
||||
|
||||
expect(result.finished).toEqual(true);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"meta": {
|
||||
"instanceId": "104a4d08d8897b8bdeb38aaca515021075e0bd8544c983c2bb8c86e6a8e6081c"
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"parameters": {},
|
||||
"id": "01b8609f-a345-41de-80bf-6d84276b5e7a",
|
||||
"name": "When clicking \"Execute Workflow\"",
|
||||
"type": "n8n-nodes-base.manualTrigger",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
700,
|
||||
320
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"fileSelector": "C:/Test/image.jpg",
|
||||
"options": {}
|
||||
},
|
||||
"id": "a1ea0fd0-cc95-4de2-bc58-bc980cb1d97e",
|
||||
"name": "Read from Disk",
|
||||
"type": "n8n-nodes-base.readWriteFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
920,
|
||||
320
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "write",
|
||||
"fileName": "C:/Test/image-written.jpg",
|
||||
"options": {}
|
||||
},
|
||||
"id": "94abac52-bd10-4b57-85b0-691c70989137",
|
||||
"name": "Write to Disk",
|
||||
"type": "n8n-nodes-base.readWriteFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1140,
|
||||
320
|
||||
]
|
||||
}
|
||||
],
|
||||
"connections": {
|
||||
"When clicking \"Execute Workflow\"": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Read from Disk",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Read from Disk": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Write to Disk",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"pinData": {}
|
||||
}
|
||||
BIN
packages/nodes-base/nodes/Files/ReadWriteFile/test/image.jpg
Normal file
BIN
packages/nodes-base/nodes/Files/ReadWriteFile/test/image.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
@@ -0,0 +1,5 @@
|
||||
import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers';
|
||||
|
||||
const workflows = getWorkflowFilenames(__dirname);
|
||||
|
||||
describe('Test Convert to File Node', () => testWorkflows(workflows));
|
||||
@@ -0,0 +1,707 @@
|
||||
{
|
||||
"name": "convert to tests",
|
||||
"nodes": [
|
||||
{
|
||||
"parameters": {},
|
||||
"id": "35cce987-aa4f-4738-bfcd-b85098948341",
|
||||
"name": "When clicking \"Execute Workflow\"",
|
||||
"type": "n8n-nodes-base.manualTrigger",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
680,
|
||||
1100
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"fields": {
|
||||
"values": [
|
||||
{
|
||||
"name": "row_number",
|
||||
"type": "numberValue",
|
||||
"numberValue": "2"
|
||||
},
|
||||
{
|
||||
"name": "country",
|
||||
"stringValue": "uk"
|
||||
},
|
||||
{
|
||||
"name": "browser",
|
||||
"stringValue": "firefox"
|
||||
},
|
||||
{
|
||||
"name": "session_duration",
|
||||
"type": "numberValue",
|
||||
"numberValue": "1"
|
||||
},
|
||||
{
|
||||
"name": "visits",
|
||||
"type": "numberValue",
|
||||
"numberValue": "1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"include": "none",
|
||||
"options": {}
|
||||
},
|
||||
"id": "13305747-c966-4f46-90b3-ffff6835b714",
|
||||
"name": "Edit Fields",
|
||||
"type": "n8n-nodes-base.set",
|
||||
"typeVersion": 3.2,
|
||||
"position": [
|
||||
980,
|
||||
880
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"options": {}
|
||||
},
|
||||
"id": "b08b269d-0735-4dc4-b5a7-7870f5e115f9",
|
||||
"name": "Convert to File",
|
||||
"type": "n8n-nodes-base.convertToFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1380,
|
||||
420
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "html",
|
||||
"options": {}
|
||||
},
|
||||
"id": "c68c209f-771f-4d25-b832-3d55ee97e6ff",
|
||||
"name": "Convert to File1",
|
||||
"type": "n8n-nodes-base.convertToFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1380,
|
||||
600
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "toJson",
|
||||
"options": {}
|
||||
},
|
||||
"id": "2b6f27ed-a4dc-4a29-905f-f0a921ea6ee7",
|
||||
"name": "Convert to File2",
|
||||
"type": "n8n-nodes-base.convertToFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1380,
|
||||
780
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "toJson",
|
||||
"mode": "each",
|
||||
"options": {}
|
||||
},
|
||||
"id": "cd482d12-7547-4eb6-880b-bd2c31ef06d5",
|
||||
"name": "Convert to File3",
|
||||
"type": "n8n-nodes-base.convertToFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1380,
|
||||
960
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "xlsx",
|
||||
"options": {}
|
||||
},
|
||||
"id": "1fd693e3-4286-49f4-ba45-70584c1d67f7",
|
||||
"name": "Convert to File5",
|
||||
"type": "n8n-nodes-base.convertToFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1380,
|
||||
1140
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"options": {}
|
||||
},
|
||||
"id": "636866e9-ca0d-44a3-b27a-90cf33e26485",
|
||||
"name": "Extract From File",
|
||||
"type": "n8n-nodes-base.extractFromFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1600,
|
||||
420
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "html",
|
||||
"options": {}
|
||||
},
|
||||
"id": "5c66b2ea-94b2-4a1b-a34d-acb07fe33e13",
|
||||
"name": "Extract From File1",
|
||||
"type": "n8n-nodes-base.extractFromFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1600,
|
||||
600
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "fromJson",
|
||||
"options": {}
|
||||
},
|
||||
"id": "a03752f0-e3bb-4dd3-9aae-dc4d1471c281",
|
||||
"name": "Extract From File2",
|
||||
"type": "n8n-nodes-base.extractFromFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1600,
|
||||
780
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "fromJson",
|
||||
"options": {}
|
||||
},
|
||||
"id": "eb10c006-60d7-4842-b9e5-a364f42dd1ab",
|
||||
"name": "Extract From File3",
|
||||
"type": "n8n-nodes-base.extractFromFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1600,
|
||||
960
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "xlsx",
|
||||
"options": {}
|
||||
},
|
||||
"id": "64c98172-2a77-4e83-b19b-232899df8113",
|
||||
"name": "Extract From File4",
|
||||
"type": "n8n-nodes-base.extractFromFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1600,
|
||||
1140
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "xls",
|
||||
"options": {}
|
||||
},
|
||||
"id": "edbfd57e-d36b-470d-9e8d-9c7f67c131b4",
|
||||
"name": "Convert to File6",
|
||||
"type": "n8n-nodes-base.convertToFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1380,
|
||||
1320
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "xls",
|
||||
"options": {}
|
||||
},
|
||||
"id": "86713806-8dc6-45ec-a710-e80b839ec193",
|
||||
"name": "Extract From File5",
|
||||
"type": "n8n-nodes-base.extractFromFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1600,
|
||||
1320
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"fields": {
|
||||
"values": [
|
||||
{
|
||||
"name": "base64",
|
||||
"stringValue": "VGhpcyBpcyB0ZXh0IGNvbnZlcnRlZCB0byBiYXNlIDY0"
|
||||
}
|
||||
]
|
||||
},
|
||||
"include": "none",
|
||||
"options": {}
|
||||
},
|
||||
"id": "c205d380-2459-4d16-bb56-f862c53c25de",
|
||||
"name": "Edit Fields1",
|
||||
"type": "n8n-nodes-base.set",
|
||||
"typeVersion": 3.2,
|
||||
"position": [
|
||||
980,
|
||||
1060
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "toBinary",
|
||||
"sourceProperty": "base64",
|
||||
"options": {}
|
||||
},
|
||||
"id": "3f5fe04c-63cf-47d0-a7ca-d427b95a0c52",
|
||||
"name": "Convert to File7",
|
||||
"type": "n8n-nodes-base.convertToFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1380,
|
||||
1880
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "text",
|
||||
"options": {}
|
||||
},
|
||||
"id": "dbb4eae0-f0ee-4453-aed7-7d8322974c94",
|
||||
"name": "Extract From File6",
|
||||
"type": "n8n-nodes-base.extractFromFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1600,
|
||||
1880
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "ods",
|
||||
"options": {}
|
||||
},
|
||||
"id": "e3bf810d-7795-4663-82d1-768f76adc0d9",
|
||||
"name": "Convert to File8",
|
||||
"type": "n8n-nodes-base.convertToFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1380,
|
||||
1520
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "ods",
|
||||
"options": {}
|
||||
},
|
||||
"id": "7713d273-2d51-4e3e-8ac9-9a4e6013c690",
|
||||
"name": "Extract From File7",
|
||||
"type": "n8n-nodes-base.extractFromFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1600,
|
||||
1520
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "rtf",
|
||||
"options": {}
|
||||
},
|
||||
"id": "631b29cb-dcde-42cc-a514-45622923dab6",
|
||||
"name": "Convert to File9",
|
||||
"type": "n8n-nodes-base.convertToFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1380,
|
||||
1700
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "rtf",
|
||||
"options": {}
|
||||
},
|
||||
"id": "168b6586-c89d-4b0e-880e-4ddb8ea7cb2f",
|
||||
"name": "Extract From File8",
|
||||
"type": "n8n-nodes-base.extractFromFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1600,
|
||||
1700
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "iCal",
|
||||
"start": "2024-01-03T00:00:00",
|
||||
"end": "2024-01-04T00:00:00",
|
||||
"allDay": true,
|
||||
"additionalFields": {
|
||||
"description": "event description"
|
||||
}
|
||||
},
|
||||
"id": "2ba4acd9-2677-4b25-9379-48433ac5e9cc",
|
||||
"name": "Convert to File10",
|
||||
"type": "n8n-nodes-base.convertToFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1380,
|
||||
2100
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "fromIcs",
|
||||
"options": {}
|
||||
},
|
||||
"id": "c0179d40-7de0-4e42-a6bf-97c5bb764665",
|
||||
"name": "Extract From File9",
|
||||
"type": "n8n-nodes-base.extractFromFile",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
1600,
|
||||
2100
|
||||
]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"fields": {
|
||||
"values": [
|
||||
{
|
||||
"name": "description",
|
||||
"stringValue": "={{ $json.data.events[0].description }}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"include": "none",
|
||||
"options": {}
|
||||
},
|
||||
"id": "8ee98090-f3b0-41d5-8122-d27e5559738f",
|
||||
"name": "Edit Fields2",
|
||||
"type": "n8n-nodes-base.set",
|
||||
"typeVersion": 3.2,
|
||||
"position": [
|
||||
1820,
|
||||
2100
|
||||
]
|
||||
}
|
||||
],
|
||||
"pinData": {
|
||||
"Extract From File": [
|
||||
{
|
||||
"json": {
|
||||
"row_number": "2",
|
||||
"country": "uk",
|
||||
"browser": "firefox",
|
||||
"session_duration": "1",
|
||||
"visits": "1"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Extract From File1": [
|
||||
{
|
||||
"json": {
|
||||
"row_number": 2,
|
||||
"country": "uk",
|
||||
"browser": "firefox",
|
||||
"session_duration": 1,
|
||||
"visits": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"Extract From File2": [
|
||||
{
|
||||
"json": {
|
||||
"data": [
|
||||
{
|
||||
"row_number": 2,
|
||||
"country": "uk",
|
||||
"browser": "firefox",
|
||||
"session_duration": 1,
|
||||
"visits": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"Extract From File3": [
|
||||
{
|
||||
"json": {
|
||||
"data": {
|
||||
"row_number": 2,
|
||||
"country": "uk",
|
||||
"browser": "firefox",
|
||||
"session_duration": 1,
|
||||
"visits": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"Extract From File4": [
|
||||
{
|
||||
"json": {
|
||||
"row_number": 2,
|
||||
"country": "uk",
|
||||
"browser": "firefox",
|
||||
"session_duration": 1,
|
||||
"visits": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"Extract From File5": [
|
||||
{
|
||||
"json": {
|
||||
"row_number": 2,
|
||||
"country": "uk",
|
||||
"browser": "firefox",
|
||||
"session_duration": 1,
|
||||
"visits": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"Extract From File7": [
|
||||
{
|
||||
"json": {
|
||||
"row_number": 2,
|
||||
"country": "uk",
|
||||
"browser": "firefox",
|
||||
"session_duration": 1,
|
||||
"visits": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"Extract From File6": [
|
||||
{
|
||||
"json": {
|
||||
"data": "This is text converted to base 64"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Extract From File8": [
|
||||
{
|
||||
"json": {
|
||||
"row_number": 2,
|
||||
"country": "uk",
|
||||
"browser": "firefox",
|
||||
"session_duration": 1,
|
||||
"visits": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"Edit Fields2": [
|
||||
{
|
||||
"json": {
|
||||
"description": "event description"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"connections": {
|
||||
"When clicking \"Execute Workflow\"": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Edit Fields",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"node": "Edit Fields1",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"node": "Convert to File10",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Edit Fields": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Convert to File",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"node": "Convert to File1",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"node": "Convert to File2",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"node": "Convert to File3",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"node": "Convert to File5",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"node": "Convert to File6",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"node": "Convert to File8",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"node": "Convert to File9",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Convert to File": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Extract From File",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Convert to File1": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Extract From File1",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Convert to File2": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Extract From File2",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Convert to File3": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Extract From File3",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Convert to File5": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Extract From File4",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Convert to File6": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Extract From File5",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Convert to File7": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Extract From File6",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Edit Fields1": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Convert to File7",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Convert to File8": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Extract From File7",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Convert to File9": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Extract From File8",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Convert to File10": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Extract From File9",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Extract From File9": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Edit Fields2",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"active": false,
|
||||
"settings": {
|
||||
"executionOrder": "v1"
|
||||
},
|
||||
"versionId": "3287cce3-f02f-45df-9d3b-2f116852c1fb",
|
||||
"meta": {
|
||||
"instanceId": "b888bd11cd1ddbb95450babf3e199556799d999b896f650de768b8370ee50363"
|
||||
},
|
||||
"id": "ZzoOtOee7hxaNcmp",
|
||||
"tags": []
|
||||
}
|
||||
Reference in New Issue
Block a user