mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
🐛 Fix issue with wrongly named binary data #423
This commit is contained in:
parent
8e57009b3b
commit
554a32d64d
|
@ -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,
|
||||
]
|
||||
],
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue