From 92cfbcb382bbe8ed7fb00385589278a84b53206b Mon Sep 17 00:00:00 2001 From: Stephen Hu Date: Fri, 18 Jul 2025 17:06:58 +0800 Subject: [PATCH] Fix: when parse markdown support extract image at local (#8906) ### What problem does this PR solve? https://github.com/infiniflow/ragflow/issues/8902 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- rag/app/naive.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/rag/app/naive.py b/rag/app/naive.py index db1acc0eb..7873e63b9 100644 --- a/rag/app/naive.py +++ b/rag/app/naive.py @@ -313,9 +313,21 @@ class Markdown(MarkdownParser): # Find all image URLs in text for url in image_urls: try: - response = requests.get(url, stream=True, timeout=30) - if response.status_code == 200 and response.headers['Content-Type'].startswith('image/'): - img = Image.open(BytesIO(response.content)).convert('RGB') + # check if the url is a local file or a remote URL + if url.startswith(('http://', 'https://')): + # For remote URLs, download the image + response = requests.get(url, stream=True, timeout=30) + if response.status_code == 200 and response.headers['Content-Type'].startswith('image/'): + img = Image.open(BytesIO(response.content)).convert('RGB') + images.append(img) + else: + # For local file paths, open the image directly + from pathlib import Path + local_path = Path(url) + if not local_path.exists(): + logging.warning(f"Local image file not found: {url}") + continue + img = Image.open(url).convert('RGB') images.append(img) except Exception as e: logging.error(f"Failed to download/open image from {url}: {e}")