From bc77bbd1ba2767c1cc83a050e0f52351c190deae Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Wed, 15 Oct 2025 16:20:54 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=82=20refactor:=20OCR=20Fallback=20for?= =?UTF-8?q?=20"Upload=20as=20Text"=20File=20Process=20(#10126)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/server/services/Files/process.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/api/server/services/Files/process.js b/api/server/services/Files/process.js index 5e945f0e36..701412523d 100644 --- a/api/server/services/Files/process.js +++ b/api/server/services/Files/process.js @@ -598,11 +598,22 @@ const processAgentFileUpload = async ({ req, res, metadata }) => { if (shouldUseOCR && !(await checkCapability(req, AgentCapabilities.ocr))) { throw new Error('OCR capability is not enabled for Agents'); } else if (shouldUseOCR) { - const { handleFileUpload: uploadOCR } = getStrategyFunctions( - appConfig?.ocr?.strategy ?? FileSources.mistral_ocr, - ); - const { text, bytes, filepath: ocrFileURL } = await uploadOCR({ req, file, loadAuthValues }); - return await createTextFile({ text, bytes, filepath: ocrFileURL }); + try { + const { handleFileUpload: uploadOCR } = getStrategyFunctions( + appConfig?.ocr?.strategy ?? FileSources.mistral_ocr, + ); + const { + text, + bytes, + filepath: ocrFileURL, + } = await uploadOCR({ req, file, loadAuthValues }); + return await createTextFile({ text, bytes, filepath: ocrFileURL }); + } catch (ocrError) { + logger.error( + `[processAgentFileUpload] OCR processing failed for file "${file.originalname}", falling back to text extraction:`, + ocrError, + ); + } } const shouldUseSTT = fileConfig.checkType(