🔀 Merge branch 'RicardoE105-feature/webhook-multipart-data'

This commit is contained in:
Jan Oberhauser 2020-02-06 21:33:15 -08:00
commit e742c8695b

View file

@ -14,6 +14,12 @@ import * as basicAuth from 'basic-auth';
import { Response } from 'express';
import { set } from 'lodash';
import * as fs from 'fs';
import * as formidable from 'formidable';
function authorizationError(resp: Response, realm: string, responseCode: number, message?: string) {
if (message === undefined) {
message = 'Authorization problem!';
@ -307,6 +313,37 @@ 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();
return new Promise((resolve, reject) => {
form.parse(req, async (err, data, files) => {
const returnData: INodeExecutionData[] = this.helpers.returnJsonArray({
body: data,
headers,
query: this.getQueryData(),
});
for (const file of Object.keys(files)) {
const fileJson = files[file].toJSON() as IDataObject;
const [fileName, fileExtension] = (fileJson.name as string).split('.');
const fileContent = await fs.promises.readFile(files[file].path);
set(returnData[0], `binary[${fileName}]`, {
data: fileContent,
mimeType: fileJson.type,
fileName: fileJson.name,
fileExtension,
});
}
resolve({
workflowData: [
returnData,
],
});
});
});
}
const response: INodeExecutionData = {
json: {