🐛 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',
@ -355,26 +357,35 @@ export class Webhook implements INodeType {
return new Promise((resolve, reject) => {
form.parse(req, async (err, data, files) => {
const returnData: INodeExecutionData[] = this.helpers.returnJsonArray({
body: data,
headers,
query: this.getQueryData(),
});
const returnItem: INodeExecutionData = {
binary: {},
json: {
body: this.getBodyData(),
headers,
query: this.getQueryData(),
},
};
let count = 0;
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 [fileName, fileExtension] = (fileJson.name as string).split('.');
const fileContent = await fs.promises.readFile(files[file].path);
const buffer = Buffer.from(fileContent);
set(returnData[0], `binary[${fileName}]`, {
data: buffer.toString(BINARY_ENCODING),
mimeType: fileJson.type,
fileName: fileJson.name,
fileExtension,
});
returnItem.binary![binaryPropertyName] = await this.helpers.prepareBinaryData(Buffer.from(fileContent), fileJson.name as string, fileJson.type as string);
count += 1;
}
resolve({
workflowData: [
returnData,
[
returnItem,
]
],
});
});