mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
🔀 Merge branch 'RicardoE105-feature/extend-http-request'
This commit is contained in:
commit
60826ba19d
|
@ -7,6 +7,7 @@ import {
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
|
IBinaryData,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import { OptionsWithUri } from 'request';
|
import { OptionsWithUri } from 'request';
|
||||||
|
@ -356,7 +357,9 @@ export class HttpRequest implements INodeType {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: 'Name of the binary property which contains<br />the data for the file to be uploaded.',
|
description: `Name of the binary property which contains the data for the file to be uploaded.<br />
|
||||||
|
For Form-Data Multipart, multiple can be provided in the format:<br />
|
||||||
|
"sendKey1:binaryProperty1,sendKey2:binaryProperty2`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Body Parameters',
|
displayName: 'Body Parameters',
|
||||||
|
@ -636,10 +639,15 @@ export class HttpRequest implements INodeType {
|
||||||
const sendBinaryData = this.getNodeParameter('sendBinaryData', itemIndex, false) as boolean;
|
const sendBinaryData = this.getNodeParameter('sendBinaryData', itemIndex, false) as boolean;
|
||||||
if (sendBinaryData === true) {
|
if (sendBinaryData === true) {
|
||||||
|
|
||||||
if (options.bodyContentType !== 'raw') {
|
const contentTypesAllowed = [
|
||||||
|
'raw',
|
||||||
|
'multipart-form-data',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!contentTypesAllowed.includes(options.bodyContentType as string)) {
|
||||||
// As n8n-workflow.NodeHelpers.getParamterResolveOrder can not be changed
|
// As n8n-workflow.NodeHelpers.getParamterResolveOrder can not be changed
|
||||||
// easily to handle parameters in dot.notation simply error for now.
|
// easily to handle parameters in dot.notation simply error for now.
|
||||||
throw new Error('Sending binary data is only supported when option "Body Content Type" is set to "RAW/CUSTOM"!');
|
throw new Error('Sending binary data is only supported when option "Body Content Type" is set to "RAW/CUSTOM" or "FORM-DATA/MULTIPART"!');
|
||||||
}
|
}
|
||||||
|
|
||||||
const item = items[itemIndex];
|
const item = items[itemIndex];
|
||||||
|
@ -648,12 +656,44 @@ export class HttpRequest implements INodeType {
|
||||||
throw new Error('No binary data exists on item!');
|
throw new Error('No binary data exists on item!');
|
||||||
}
|
}
|
||||||
|
|
||||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex) as string;
|
if (options.bodyContentType === 'raw') {
|
||||||
if (item.binary[binaryPropertyName] === undefined) {
|
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex) as string;
|
||||||
throw new Error(`No binary data property "${binaryPropertyName}" does not exists on item!`);
|
if (item.binary[binaryPropertyName] === undefined) {
|
||||||
}
|
throw new Error(`No binary data property "${binaryPropertyName}" does not exists on item!`);
|
||||||
|
}
|
||||||
|
const binaryProperty = item.binary[binaryPropertyName] as IBinaryData;
|
||||||
|
requestOptions.body = Buffer.from(binaryProperty.data, BINARY_ENCODING);
|
||||||
|
} else if (options.bodyContentType === 'multipart-form-data') {
|
||||||
|
requestOptions.body = {};
|
||||||
|
const binaryPropertyNameFull = this.getNodeParameter('binaryPropertyName', itemIndex) as string;
|
||||||
|
const binaryPropertyNames = binaryPropertyNameFull.split(',').map(key => key.trim());
|
||||||
|
|
||||||
requestOptions.body = Buffer.from(item.binary[binaryPropertyName].data, BINARY_ENCODING);
|
for (const propertyData of binaryPropertyNames) {
|
||||||
|
let propertyName = 'file';
|
||||||
|
let binaryPropertyName = propertyData;
|
||||||
|
if (propertyData.includes(':')) {
|
||||||
|
const propertyDataParts = propertyData.split(':');
|
||||||
|
propertyName = propertyDataParts[0];
|
||||||
|
binaryPropertyName = propertyDataParts[1];
|
||||||
|
} else if (binaryPropertyNames.length > 1) {
|
||||||
|
throw new Error('If more than one property should be send it is needed to define the in the format: "sendKey1:binaryProperty1,sendKey2:binaryProperty2"');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.binary[binaryPropertyName] === undefined) {
|
||||||
|
throw new Error(`No binary data property "${binaryPropertyName}" does not exists on item!`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const binaryProperty = item.binary[binaryPropertyName] as IBinaryData;
|
||||||
|
|
||||||
|
requestOptions.body[propertyName] = {
|
||||||
|
value: Buffer.from(binaryProperty.data, BINARY_ENCODING),
|
||||||
|
options: {
|
||||||
|
filename: binaryProperty.fileName,
|
||||||
|
contentType: binaryProperty.mimeType,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue