Skip to content

Commit 41fdcdb

Browse files
fix(knowledge): accept relative internal file URLs in document processor (#5499)
1 parent aad2544 commit 41fdcdb

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

apps/sim/lib/knowledge/documents/document-processor.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,12 @@ async function downloadFileForBase64(fileUrl: string, userId?: string): Promise<
403403
}
404404
return Buffer.from(base64Data, 'base64')
405405
}
406-
if (/^https?:\/\//i.test(fileUrl)) {
406+
if (/^https?:\/\//i.test(fileUrl) || isInternalFileUrl(fileUrl)) {
407407
return downloadFileWithTimeout(fileUrl, userId)
408408
}
409-
throw new Error('Unsupported fileUrl scheme: only data: URIs and http(s):// URLs are allowed')
409+
throw new Error(
410+
'Unsupported fileUrl scheme: only data: URIs, http(s):// URLs, and internal /api/files/serve/ paths are allowed'
411+
)
410412
}
411413

412414
function processOCRContent(result: OCRResult, filename: string): string {
@@ -801,12 +803,17 @@ async function parseWithFileParser(
801803

802804
if (/^data:/i.test(fileUrl)) {
803805
content = await parseDataURI(fileUrl, filename, mimeType)
804-
} else if (/^https?:\/\//i.test(fileUrl)) {
806+
} else if (/^https?:\/\//i.test(fileUrl) || isInternalFileUrl(fileUrl)) {
807+
// Internal URLs may arrive as an app-relative `/api/files/serve/...` path
808+
// (some ingestion callers store the relative path); downloadFileFromUrl
809+
// resolves it directly against storage without an absolute origin.
805810
const result = await parseHttpFile(fileUrl, filename, mimeType, userId)
806811
content = result.content
807812
metadata = result.metadata || {}
808813
} else {
809-
throw new Error('Unsupported fileUrl scheme: only data: URIs and http(s):// URLs are allowed')
814+
throw new Error(
815+
'Unsupported fileUrl scheme: only data: URIs, http(s):// URLs, and internal /api/files/serve/ paths are allowed'
816+
)
810817
}
811818

812819
if (!content.trim()) {

0 commit comments

Comments
 (0)