From f96b4941751c064cf952513e1c292e1ef446d699 Mon Sep 17 00:00:00 2001 From: Michael Kret Date: Thu, 8 Feb 2024 10:32:25 +0200 Subject: [PATCH 1/2] :zap: fix --- .../HttpRequest/V3/HttpRequestV3.node.ts | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts b/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts index 295761af12fba..44591bff69c77 100644 --- a/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts +++ b/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts @@ -1810,8 +1810,9 @@ export class HttpRequestV3 implements INodeType { } } + let responseContentType = ''; if (autoDetectResponseFormat) { - const responseContentType = response.headers['content-type'] ?? ''; + responseContentType = response.headers['content-type'] ?? ''; if (responseContentType.includes('application/json')) { responseFormat = 'json'; if (!response.__bodyResolved) { @@ -1890,7 +1891,22 @@ export class HttpRequestV3 implements INodeType { newItem.json = items[itemIndex].json; binaryData = response; } - newItem.binary![outputPropertyName] = await this.helpers.prepareBinaryData(binaryData); + const preparedBinaryData = await this.helpers.prepareBinaryData( + binaryData, + undefined, + responseContentType || undefined, + ); + + if ( + !preparedBinaryData.fileName && + preparedBinaryData.fileExtension && + typeof requestOptions.uri === 'string' && + requestOptions.uri.endsWith(preparedBinaryData.fileExtension) + ) { + preparedBinaryData.fileName = requestOptions.uri.split('/').pop(); + } + + newItem.binary![outputPropertyName] = preparedBinaryData; returnItems.push(newItem); } else if (responseFormat === 'text') { From ce78c830ff647e056bbb91944e599047864d276c Mon Sep 17 00:00:00 2001 From: Marcus Date: Thu, 8 Feb 2024 16:51:47 +0100 Subject: [PATCH 2/2] use content-type for both Autodetect and File response --- packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts b/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts index 44591bff69c77..0d75c74c00d6e 100644 --- a/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts +++ b/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts @@ -1810,9 +1810,8 @@ export class HttpRequestV3 implements INodeType { } } - let responseContentType = ''; + const responseContentType = response.headers['content-type'] ?? ''; if (autoDetectResponseFormat) { - responseContentType = response.headers['content-type'] ?? ''; if (responseContentType.includes('application/json')) { responseFormat = 'json'; if (!response.__bodyResolved) {