Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

fix: streamline temporary file handling for image and PDF processing in fast_api.py

myhloli679dad3aac07
diff --git a/mineru/cli/fast_api.py b/mineru/cli/fast_api.py
index 568c9611..4b1eb3b1 100644
--- a/mineru/cli/fast_api.py
+++ b/mineru/cli/fast_api.py
@@ -96,14 +96,14 @@ async def parse_pdf(
content = await file.read()
file_path = Path(file.filename)
+ # 创建临时文件
+ temp_path = Path(unique_dir) / file_path.name
+ with open(temp_path, "wb") as f:
+ f.write(content)
+
# 如果是图像文件或PDF,使用read_fn处理
- file_suffix = guess_suffix_by_path(file_path)
+ file_suffix = guess_suffix_by_path(temp_path)
if file_suffix in pdf_suffixes + image_suffixes:
- # 创建临时文件以便使用read_fn
- temp_path = Path(unique_dir) / file_path.name
- with open(temp_path, "wb") as f:
- f.write(content)
-
try:
pdf_bytes = read_fn(temp_path)
pdf_bytes_list.append(pdf_bytes)