🐛 Fix issue with wrongly named binary data #423

This commit is contained in:
Jan Oberhauser 2020-03-30 14:53:42 +02:00
parent 8e57009b3b
commit 554a32d64d

View file

@ -246,7 +246,9 @@ export class Webhook implements INodeType {
], ],
}, },
}, },
description: 'Name of the binary property to which to<br />write the data of the received file.', description: `Name of the binary property to which to write the data of<br />
the received file. If the data gets received via "Form-Data Multipart"<br />
it will be the prefix and a number starting with 0 will be attached to it.`,
}, },
{ {
displayName: 'Response Content-Type', displayName: 'Response Content-Type',
@ -355,26 +357,35 @@ export class Webhook implements INodeType {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
form.parse(req, async (err, data, files) => { form.parse(req, async (err, data, files) => {
const returnData: INodeExecutionData[] = this.helpers.returnJsonArray({ const returnItem: INodeExecutionData = {
body: data, binary: {},
headers, json: {
query: this.getQueryData(), body: this.getBodyData(),
}); headers,
query: this.getQueryData(),
},
};
let count = 0;
for (const file of Object.keys(files)) { for (const file of Object.keys(files)) {
let binaryPropertyName = file;
if (options.binaryPropertyName) {
binaryPropertyName = `${options.binaryPropertyName}${count}`;
}
const fileJson = files[file].toJSON() as IDataObject; const fileJson = files[file].toJSON() as IDataObject;
const [fileName, fileExtension] = (fileJson.name as string).split('.');
const fileContent = await fs.promises.readFile(files[file].path); const fileContent = await fs.promises.readFile(files[file].path);
const buffer = Buffer.from(fileContent);
set(returnData[0], `binary[${fileName}]`, { returnItem.binary![binaryPropertyName] = await this.helpers.prepareBinaryData(Buffer.from(fileContent), fileJson.name as string, fileJson.type as string);
data: buffer.toString(BINARY_ENCODING),
mimeType: fileJson.type, count += 1;
fileName: fileJson.name,
fileExtension,
});
} }
resolve({ resolve({
workflowData: [ workflowData: [
returnData, [
returnItem,
]
], ],
}); });
}); });