mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
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)
This commit is contained in:
@ -313,10 +313,22 @@ class Markdown(MarkdownParser):
|
|||||||
# Find all image URLs in text
|
# Find all image URLs in text
|
||||||
for url in image_urls:
|
for url in image_urls:
|
||||||
try:
|
try:
|
||||||
|
# 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)
|
response = requests.get(url, stream=True, timeout=30)
|
||||||
if response.status_code == 200 and response.headers['Content-Type'].startswith('image/'):
|
if response.status_code == 200 and response.headers['Content-Type'].startswith('image/'):
|
||||||
img = Image.open(BytesIO(response.content)).convert('RGB')
|
img = Image.open(BytesIO(response.content)).convert('RGB')
|
||||||
images.append(img)
|
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:
|
except Exception as e:
|
||||||
logging.error(f"Failed to download/open image from {url}: {e}")
|
logging.error(f"Failed to download/open image from {url}: {e}")
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user