mirror of
https://github.com/n8n-io/n8n.git
synced 2024-09-20 14:57:31 -07:00
⚡ Improve Webhook receive binary functionality
This commit is contained in:
parent
4d5a8234b5
commit
1534335b58
|
@ -212,28 +212,6 @@ export class Webhook implements INodeType {
|
|||
},
|
||||
description: 'Name of the binary property to return',
|
||||
},
|
||||
{
|
||||
displayName: 'Binary Data',
|
||||
name: 'binaryData',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'If the data to upload should be taken from binary field.',
|
||||
},
|
||||
{
|
||||
displayName: 'Binary Property',
|
||||
name: 'binaryPropertyName',
|
||||
type: 'string',
|
||||
default: 'data',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
binaryData: [
|
||||
true,
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'Name of the binary property which contains<br />the data for the file to be uploaded.',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
|
@ -241,6 +219,35 @@ export class Webhook implements INodeType {
|
|||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Binary Data',
|
||||
name: 'binaryData',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'/httpMethod': [
|
||||
'POST',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Set to true if webhook will receive binary data.',
|
||||
},
|
||||
{
|
||||
displayName: 'Binary Property',
|
||||
name: 'binaryPropertyName',
|
||||
type: 'string',
|
||||
default: 'data',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
binaryData: [
|
||||
true,
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'Name of the binary property to which to<br />write the data of the received file.',
|
||||
},
|
||||
{
|
||||
displayName: 'Response Content-Type',
|
||||
name: 'responseContentType',
|
||||
|
@ -280,6 +287,13 @@ export class Webhook implements INodeType {
|
|||
displayName: 'Raw Body',
|
||||
name: 'rawBody',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
hide: {
|
||||
binaryData: [
|
||||
true,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Raw body (binary)',
|
||||
},
|
||||
|
@ -289,9 +303,8 @@ export class Webhook implements INodeType {
|
|||
};
|
||||
|
||||
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
||||
const authentication = this.getNodeParameter('authentication', 0) as string;
|
||||
const options = this.getNodeParameter('options', 0) as IDataObject;
|
||||
const binaryData = this.getNodeParameter('binaryData', 0) as boolean;
|
||||
const authentication = this.getNodeParameter('authentication') as string;
|
||||
const options = this.getNodeParameter('options', {}) as IDataObject;
|
||||
const req = this.getRequestObject();
|
||||
const resp = this.getResponseObject();
|
||||
const headers = this.getHeaderData();
|
||||
|
@ -369,24 +382,33 @@ export class Webhook implements INodeType {
|
|||
});
|
||||
}
|
||||
|
||||
if (binaryData) {
|
||||
if (options.binaryData === true) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0) as string;
|
||||
const binaryPropertyName = options.binaryPropertyName || 'data';
|
||||
const data: Buffer[] = [];
|
||||
|
||||
req.on('data', (chunk) => {
|
||||
data.push(chunk);
|
||||
});
|
||||
|
||||
req.on('end', () => {
|
||||
const returnData: IDataObject[] = [{}];
|
||||
req.on('end', async () => {
|
||||
const returnItem: INodeExecutionData = {
|
||||
binary: {},
|
||||
json: {},
|
||||
};
|
||||
|
||||
const returnData: IDataObject[] = [{ json: {} }];
|
||||
set(returnData[0], `binary[${binaryPropertyName}]`, {
|
||||
data: Buffer.concat(data).toString('base64'),
|
||||
data: Buffer.concat(data).toString(BINARY_ENCODING),
|
||||
mimeType: req.headers['content-type'],
|
||||
});
|
||||
returnItem.binary![binaryPropertyName as string] = await this.helpers.prepareBinaryData(Buffer.concat(data));
|
||||
|
||||
return resolve({
|
||||
workflowData: [
|
||||
returnData as INodeExecutionData[],
|
||||
[
|
||||
returnItem
|
||||
]
|
||||
],
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue