mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-24 04:59:13 +00:00
feat(HTTP Request Node): Determine binary file name from content-disposition headers (#7032)
Fixes: https://community.n8n.io/t/http-request-node-read-filename-from-content-disposition-header-when-downloading-files/13453 https://community.n8n.io/t/read-filename-from-content-disposition-header-when-downloading-files/22192
This commit is contained in:
committed by
GitHub
parent
25dc4d7825
commit
273d0913fe
@@ -71,8 +71,6 @@
|
||||
"@types/bcryptjs": "^2.4.2",
|
||||
"@types/compression": "1.0.1",
|
||||
"@types/connect-history-api-fallback": "^1.3.1",
|
||||
"@types/content-disposition": "^0.5.5",
|
||||
"@types/content-type": "^1.1.5",
|
||||
"@types/convict": "^6.1.1",
|
||||
"@types/cookie-parser": "^1.4.2",
|
||||
"@types/express": "^4.17.6",
|
||||
@@ -121,8 +119,6 @@
|
||||
"class-validator": "^0.14.0",
|
||||
"compression": "^1.7.4",
|
||||
"connect-history-api-fallback": "^1.6.0",
|
||||
"content-disposition": "^0.5.4",
|
||||
"content-type": "^1.0.4",
|
||||
"convict": "^6.2.4",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"crypto-js": "~4.1.1",
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { parse as parseContentDisposition } from 'content-disposition';
|
||||
import { parse as parseContentType } from 'content-type';
|
||||
import getRawBody from 'raw-body';
|
||||
import type { Request, RequestHandler } from 'express';
|
||||
import { parse as parseQueryString } from 'querystring';
|
||||
import { Parser as XmlParser } from 'xml2js';
|
||||
import { parseIncomingMessage } from 'n8n-core';
|
||||
import { jsonParse } from 'n8n-workflow';
|
||||
import config from '@/config';
|
||||
import { UnprocessableRequestError } from '@/ResponseHelper';
|
||||
@@ -17,26 +16,7 @@ const xmlParser = new XmlParser({
|
||||
|
||||
const payloadSizeMax = config.getEnv('endpoints.payloadSizeMax');
|
||||
export const rawBodyReader: RequestHandler = async (req, res, next) => {
|
||||
if ('content-type' in req.headers) {
|
||||
const { type: contentType, parameters } = (() => {
|
||||
try {
|
||||
return parseContentType(req);
|
||||
} catch {
|
||||
return { type: undefined, parameters: undefined };
|
||||
}
|
||||
})();
|
||||
req.contentType = contentType;
|
||||
req.encoding = (parameters?.charset ?? 'utf-8').toLowerCase() as BufferEncoding;
|
||||
|
||||
const contentDispositionHeader = req.headers['content-disposition'];
|
||||
if (contentDispositionHeader?.length) {
|
||||
const {
|
||||
type,
|
||||
parameters: { filename },
|
||||
} = parseContentDisposition(contentDispositionHeader);
|
||||
req.contentDisposition = { type, filename };
|
||||
}
|
||||
}
|
||||
parseIncomingMessage(req);
|
||||
|
||||
req.readRawBody = async () => {
|
||||
if (!req.rawBody) {
|
||||
|
||||
Reference in New Issue
Block a user