fix(Telegram Node): Determine the MIME type when downloading the file (#17725)

This commit is contained in:
RomanDavydchuk
2025-07-28 11:31:15 +03:00
committed by GitHub
parent e1aa60ce6f
commit a9c29e340a
2 changed files with 219 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
import { lookup } from 'mime-types';
import type {
IExecuteFunctions,
IDataObject,
@@ -656,6 +657,31 @@ export class Telegram implements INodeType {
default: true,
description: 'Whether to download the file',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: ['get'],
resource: ['file'],
download: [true],
},
},
default: {},
options: [
{
displayName: 'MIME Type',
name: 'mimeType',
type: 'string',
placeholder: 'image/jpeg',
default: '',
description:
'The MIME type of the file. If not specified, the MIME type will be determined by the file extension.',
},
],
},
// ----------------------------------
// message
@@ -2169,11 +2195,15 @@ export class Telegram implements INodeType {
},
);
const fileName = filePath.split('/').pop();
const fileName = filePath.split('/').pop() as string;
const additionalFields = this.getNodeParameter('additionalFields', 0);
const providedMimeType = additionalFields?.mimeType as string | undefined;
const mimeType = providedMimeType ?? (lookup(fileName) || 'application/octet-stream');
const data = await this.helpers.prepareBinaryData(
file.body as Buffer,
fileName as string,
fileName,
mimeType,
);
returnData.push({