mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(HTTP Request Node): Detect mime-type from streaming responses (#5896)
This commit is contained in:
parent
b1ee8f4d99
commit
0be129254e
|
@ -77,6 +77,7 @@ import {
|
||||||
|
|
||||||
import pick from 'lodash.pick';
|
import pick from 'lodash.pick';
|
||||||
import { Agent } from 'https';
|
import { Agent } from 'https';
|
||||||
|
import { IncomingMessage } from 'http';
|
||||||
import { stringify } from 'qs';
|
import { stringify } from 'qs';
|
||||||
import type { Token } from 'oauth-1.0a';
|
import type { Token } from 'oauth-1.0a';
|
||||||
import clientOAuth1 from 'oauth-1.0a';
|
import clientOAuth1 from 'oauth-1.0a';
|
||||||
|
@ -932,14 +933,16 @@ export async function copyBinaryFile(
|
||||||
fileExtension = fileTypeData.ext;
|
fileExtension = fileTypeData.ext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fileExtension && mimeType) {
|
||||||
|
fileExtension = extension(mimeType) || undefined;
|
||||||
|
}
|
||||||
|
|
||||||
if (!mimeType) {
|
if (!mimeType) {
|
||||||
// Fall back to text
|
// Fall back to text
|
||||||
mimeType = 'text/plain';
|
mimeType = 'text/plain';
|
||||||
}
|
}
|
||||||
} else if (!fileExtension) {
|
|
||||||
fileExtension = extension(mimeType) || undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const returnData: IBinaryData = {
|
const returnData: IBinaryData = {
|
||||||
mimeType,
|
mimeType,
|
||||||
|
@ -979,23 +982,30 @@ async function prepareBinaryData(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: detect filetype from streams
|
if (!mimeType) {
|
||||||
if (!mimeType && Buffer.isBuffer(binaryData)) {
|
if (Buffer.isBuffer(binaryData)) {
|
||||||
// Use buffer to guess mime type
|
// Use buffer to guess mime type
|
||||||
const fileTypeData = await FileType.fromBuffer(binaryData);
|
const fileTypeData = await FileType.fromBuffer(binaryData);
|
||||||
if (fileTypeData) {
|
if (fileTypeData) {
|
||||||
mimeType = fileTypeData.mime;
|
mimeType = fileTypeData.mime;
|
||||||
fileExtension = fileTypeData.ext;
|
fileExtension = fileTypeData.ext;
|
||||||
}
|
}
|
||||||
|
} else if (binaryData instanceof IncomingMessage) {
|
||||||
|
mimeType = binaryData.headers['content-type'];
|
||||||
|
} else {
|
||||||
|
// TODO: detect filetype from other kind of streams
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fileExtension && mimeType) {
|
||||||
|
fileExtension = extension(mimeType) || undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mimeType) {
|
if (!mimeType) {
|
||||||
// Fall back to text
|
// Fall back to text
|
||||||
mimeType = 'text/plain';
|
mimeType = 'text/plain';
|
||||||
}
|
}
|
||||||
} else if (!fileExtension) {
|
|
||||||
fileExtension = extension(mimeType) || undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const returnData: IBinaryData = {
|
const returnData: IBinaryData = {
|
||||||
mimeType,
|
mimeType,
|
||||||
|
|
Loading…
Reference in a new issue