mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +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 {
|
||||
IExecuteFunctions,
|
||||
IDataObject,
|
||||
@@ -632,7 +634,7 @@ export class HttpRequestV1 implements INodeType {
|
||||
oAuth2Api = await this.getCredentials('oAuth2Api');
|
||||
} catch {}
|
||||
|
||||
let requestOptions: OptionsWithUri;
|
||||
let requestOptions: OptionsWithUri & { useStream?: boolean };
|
||||
let setUiParameter: IDataObject;
|
||||
|
||||
const uiParameters: IDataObject = {
|
||||
@@ -873,6 +875,7 @@ export class HttpRequestV1 implements INodeType {
|
||||
|
||||
if (responseFormat === 'file') {
|
||||
requestOptions.encoding = null;
|
||||
requestOptions.useStream = true;
|
||||
|
||||
if (options.bodyContentType !== 'raw') {
|
||||
requestOptions.body = JSON.stringify(requestOptions.body);
|
||||
@@ -885,6 +888,7 @@ export class HttpRequestV1 implements INodeType {
|
||||
}
|
||||
} else if (options.bodyContentType === 'raw') {
|
||||
requestOptions.json = false;
|
||||
requestOptions.useStream = true;
|
||||
} else {
|
||||
requestOptions.json = true;
|
||||
}
|
||||
@@ -991,7 +995,6 @@ export class HttpRequestV1 implements INodeType {
|
||||
response = response.value;
|
||||
|
||||
const options = this.getNodeParameter('options', itemIndex, {});
|
||||
const url = this.getNodeParameter('url', itemIndex) as string;
|
||||
|
||||
const fullResponse = !!options.fullResponse;
|
||||
|
||||
@@ -1014,8 +1017,7 @@ export class HttpRequestV1 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) {
|
||||
@@ -1026,20 +1028,13 @@ export class HttpRequestV1 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