mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
✨ multipart data
This commit is contained in:
parent
24a3a02180
commit
ec3421266f
|
@ -8,12 +8,21 @@ import {
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
INodeType,
|
INodeType,
|
||||||
IWebhookResponseData,
|
IWebhookResponseData,
|
||||||
|
IRunExecutionData,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import * as basicAuth from 'basic-auth';
|
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';
|
||||||
|
import { kgsearch } from 'googleapis/build/src/apis/kgsearch';
|
||||||
|
import { runInThisContext } from 'vm';
|
||||||
|
|
||||||
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 +316,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 (let 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