mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
🐛 Fix issue with receiving mulitple files via Webhook-Node
This commit is contained in:
parent
223cd75685
commit
8fdb63ec1b
|
@ -692,7 +692,7 @@ export class Wait implements INodeType {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const mimeType = headers['content-type'] || 'application/json';
|
const mimeType = headers['content-type'] || 'application/json';
|
||||||
if (mimeType.includes('multipart/form-data')) {
|
if (mimeType.includes('multipart/form-data')) {
|
||||||
const form = new formidable.IncomingForm({});
|
const form = new formidable.IncomingForm({ multiples: true });
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
@ -708,20 +708,37 @@ export class Wait implements INodeType {
|
||||||
};
|
};
|
||||||
|
|
||||||
let count = 0;
|
let count = 0;
|
||||||
for (const file of Object.keys(files)) {
|
for (const xfile of Object.keys(files)) {
|
||||||
|
const processFiles = [];
|
||||||
|
let multiFile = false;
|
||||||
|
if (Array.isArray(files[xfile])) {
|
||||||
|
processFiles.push(...files[xfile] as formidable.File[]);
|
||||||
|
multiFile = true;
|
||||||
|
} else {
|
||||||
|
processFiles.push(files[xfile]);
|
||||||
|
}
|
||||||
|
|
||||||
let binaryPropertyName = file;
|
let fileCount = 0;
|
||||||
|
for (const file in processFiles) {
|
||||||
|
let binaryPropertyName = xfile;
|
||||||
|
if (binaryPropertyName.endsWith('[]')) {
|
||||||
|
binaryPropertyName = binaryPropertyName.slice(0, -2);
|
||||||
|
}
|
||||||
|
if (multiFile === true) {
|
||||||
|
binaryPropertyName += fileCount++;
|
||||||
|
}
|
||||||
if (options.binaryPropertyName) {
|
if (options.binaryPropertyName) {
|
||||||
binaryPropertyName = `${options.binaryPropertyName}${count}`;
|
binaryPropertyName = `${options.binaryPropertyName}${count}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileJson = (files[file] as formidable.File).toJSON() as unknown as IDataObject;
|
const fileJson = (processFiles[file] as formidable.File).toJSON() as unknown as IDataObject;
|
||||||
const fileContent = await fs.promises.readFile((files[file] as formidable.File).path);
|
const fileContent = await fs.promises.readFile((processFiles[file] as formidable.File).path);
|
||||||
|
|
||||||
returnItem.binary![binaryPropertyName] = await this.helpers.prepareBinaryData(Buffer.from(fileContent), fileJson.name as string, fileJson.type as string);
|
returnItem.binary![binaryPropertyName] = await this.helpers.prepareBinaryData(Buffer.from(fileContent), fileJson.name as string, fileJson.type as string);
|
||||||
|
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
resolve({
|
resolve({
|
||||||
workflowData: [
|
workflowData: [
|
||||||
[
|
[
|
||||||
|
|
|
@ -407,7 +407,7 @@ export class Webhook implements INodeType {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const mimeType = headers['content-type'] || 'application/json';
|
const mimeType = headers['content-type'] || 'application/json';
|
||||||
if (mimeType.includes('multipart/form-data')) {
|
if (mimeType.includes('multipart/form-data')) {
|
||||||
const form = new formidable.IncomingForm({});
|
const form = new formidable.IncomingForm({ multiples: true });
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
@ -423,20 +423,37 @@ export class Webhook implements INodeType {
|
||||||
};
|
};
|
||||||
|
|
||||||
let count = 0;
|
let count = 0;
|
||||||
for (const file of Object.keys(files)) {
|
for (const xfile of Object.keys(files)) {
|
||||||
|
const processFiles = [];
|
||||||
|
let multiFile = false;
|
||||||
|
if (Array.isArray(files[xfile])) {
|
||||||
|
processFiles.push(...files[xfile] as formidable.File[]);
|
||||||
|
multiFile = true;
|
||||||
|
} else {
|
||||||
|
processFiles.push(files[xfile]);
|
||||||
|
}
|
||||||
|
|
||||||
let binaryPropertyName = file;
|
let fileCount = 0;
|
||||||
|
for (const file in processFiles) {
|
||||||
|
let binaryPropertyName = xfile;
|
||||||
|
if (binaryPropertyName.endsWith('[]')) {
|
||||||
|
binaryPropertyName = binaryPropertyName.slice(0, -2);
|
||||||
|
}
|
||||||
|
if (multiFile === true) {
|
||||||
|
binaryPropertyName += fileCount++;
|
||||||
|
}
|
||||||
if (options.binaryPropertyName) {
|
if (options.binaryPropertyName) {
|
||||||
binaryPropertyName = `${options.binaryPropertyName}${count}`;
|
binaryPropertyName = `${options.binaryPropertyName}${count}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileJson = (files[file] as formidable.File).toJSON() as unknown as IDataObject;
|
const fileJson = (processFiles[file] as formidable.File).toJSON() as unknown as IDataObject;
|
||||||
const fileContent = await fs.promises.readFile((files[file] as formidable.File).path);
|
const fileContent = await fs.promises.readFile((processFiles[file] as formidable.File).path);
|
||||||
|
|
||||||
returnItem.binary![binaryPropertyName] = await this.helpers.prepareBinaryData(Buffer.from(fileContent), fileJson.name as string, fileJson.type as string);
|
returnItem.binary![binaryPropertyName] = await this.helpers.prepareBinaryData(Buffer.from(fileContent), fileJson.name as string, fileJson.type as string);
|
||||||
|
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
resolve({
|
resolve({
|
||||||
workflowData: [
|
workflowData: [
|
||||||
[
|
[
|
||||||
|
|
Loading…
Reference in a new issue