mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
🔀 Merge branch 'RicardoE105-feature/webhook-multipart-data'
This commit is contained in:
commit
e742c8695b
|
@ -14,6 +14,12 @@ import * as basicAuth from 'basic-auth';
|
||||||
|
|
||||||
import { Response } from 'express';
|
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) {
|
function authorizationError(resp: Response, realm: string, responseCode: number, message?: string) {
|
||||||
if (message === undefined) {
|
if (message === undefined) {
|
||||||
message = 'Authorization problem!';
|
message = 'Authorization problem!';
|
||||||
|
@ -307,6 +313,37 @@ 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')) {
|
||||||
|
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 = {
|
const response: INodeExecutionData = {
|
||||||
json: {
|
json: {
|
||||||
|
|
Loading…
Reference in a new issue