mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +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
@@ -1,3 +1,5 @@
|
||||
import type { Readable } from 'stream';
|
||||
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
@@ -672,7 +674,7 @@ export class HttpRequestV2 implements INodeType {
|
||||
} catch {}
|
||||
}
|
||||
|
||||
let requestOptions: OptionsWithUri;
|
||||
let requestOptions: OptionsWithUri & { useStream?: boolean };
|
||||
let setUiParameter: IDataObject;
|
||||
|
||||
const uiParameters: IDataObject = {
|
||||
@@ -913,6 +915,7 @@ export class HttpRequestV2 implements INodeType {
|
||||
|
||||
if (responseFormat === 'file') {
|
||||
requestOptions.encoding = null;
|
||||
requestOptions.useStream = true;
|
||||
|
||||
if (options.bodyContentType !== 'raw') {
|
||||
requestOptions.body = JSON.stringify(requestOptions.body);
|
||||
@@ -925,6 +928,7 @@ export class HttpRequestV2 implements INodeType {
|
||||
}
|
||||
} else if (options.bodyContentType === 'raw') {
|
||||
requestOptions.json = false;
|
||||
requestOptions.useStream = true;
|
||||
} else {
|
||||
requestOptions.json = true;
|
||||
}
|
||||
@@ -1044,7 +1048,6 @@ export class HttpRequestV2 implements INodeType {
|
||||
response = response.value;
|
||||
|
||||
const options = this.getNodeParameter('options', itemIndex, {});
|
||||
const url = this.getNodeParameter('url', itemIndex) as string;
|
||||
|
||||
const fullResponse = !!options.fullResponse;
|
||||
|
||||
@@ -1067,8 +1070,7 @@ export class HttpRequestV2 implements INodeType {
|
||||
Object.assign(newItem.binary, items[itemIndex].binary);
|
||||
}
|
||||
|
||||
const fileName = url.split('/').pop();
|
||||
|
||||
let binaryData: Buffer | Readable;
|
||||
if (fullResponse) {
|
||||
const returnItem: IDataObject = {};
|
||||
for (const property of fullResponseProperties) {
|
||||
@@ -1079,20 +1081,13 @@ export class HttpRequestV2 implements INodeType {
|
||||
}
|
||||
|
||||
newItem.json = returnItem;
|
||||
|
||||
newItem.binary![dataPropertyName] = await this.helpers.prepareBinaryData(
|
||||
response!.body as Buffer,
|
||||
fileName,
|
||||
);
|
||||
binaryData = response!.body;
|
||||
} else {
|
||||
newItem.json = items[itemIndex].json;
|
||||
|
||||
newItem.binary![dataPropertyName] = await this.helpers.prepareBinaryData(
|
||||
response! as Buffer,
|
||||
fileName,
|
||||
);
|
||||
binaryData = response;
|
||||
}
|
||||
|
||||
newItem.binary![dataPropertyName] = await this.helpers.prepareBinaryData(binaryData);
|
||||
returnItems.push(newItem);
|
||||
} else if (responseFormat === 'string') {
|
||||
const dataPropertyName = this.getNodeParameter('dataPropertyName', 0);
|
||||
|
||||
Reference in New Issue
Block a user