Skip to content

Commit

Permalink
🔀 Merge branch 'webhook-multifile-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
janober committed Aug 29, 2021
2 parents 56c4c69 + 8fdb63e commit a251b47
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 24 deletions.
41 changes: 29 additions & 12 deletions packages/nodes-base/nodes/Wait.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ export class Wait implements INodeType {
// @ts-ignore
const mimeType = headers['content-type'] || 'application/json';
if (mimeType.includes('multipart/form-data')) {
const form = new formidable.IncomingForm({});
const form = new formidable.IncomingForm({ multiples: true });

return new Promise((resolve, reject) => {

Expand All @@ -708,19 +708,36 @@ export class Wait implements INodeType {
};

let count = 0;
for (const file of Object.keys(files)) {

let binaryPropertyName = file;
if (options.binaryPropertyName) {
binaryPropertyName = `${options.binaryPropertyName}${count}`;
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]);
}

const fileJson = (files[file] as formidable.File).toJSON() as unknown as IDataObject;
const fileContent = await fs.promises.readFile((files[file] as formidable.File).path);

returnItem.binary![binaryPropertyName] = await this.helpers.prepareBinaryData(Buffer.from(fileContent), fileJson.name as string, fileJson.type as string);

count += 1;
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) {
binaryPropertyName = `${options.binaryPropertyName}${count}`;
}

const fileJson = (processFiles[file] as formidable.File).toJSON() as unknown as IDataObject;
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);

count += 1;
}
}
resolve({
workflowData: [
Expand Down
41 changes: 29 additions & 12 deletions packages/nodes-base/nodes/Webhook.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ export class Webhook implements INodeType {
// @ts-ignore
const mimeType = headers['content-type'] || 'application/json';
if (mimeType.includes('multipart/form-data')) {
const form = new formidable.IncomingForm({});
const form = new formidable.IncomingForm({ multiples: true });

return new Promise((resolve, reject) => {

Expand All @@ -423,19 +423,36 @@ export class Webhook implements INodeType {
};

let count = 0;
for (const file of Object.keys(files)) {

let binaryPropertyName = file;
if (options.binaryPropertyName) {
binaryPropertyName = `${options.binaryPropertyName}${count}`;
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]);
}

const fileJson = (files[file] as formidable.File).toJSON() as unknown as IDataObject;
const fileContent = await fs.promises.readFile((files[file] as formidable.File).path);

returnItem.binary![binaryPropertyName] = await this.helpers.prepareBinaryData(Buffer.from(fileContent), fileJson.name as string, fileJson.type as string);

count += 1;
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) {
binaryPropertyName = `${options.binaryPropertyName}${count}`;
}

const fileJson = (processFiles[file] as formidable.File).toJSON() as unknown as IDataObject;
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);

count += 1;
}
}
resolve({
workflowData: [
Expand Down

0 comments on commit a251b47

Please sign in to comment.