Browse Source

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

myhloli 2 months ago
parent
commit
679dad3aac
1 changed files with 6 additions and 6 deletions
  1. 6 6
      mineru/cli/fast_api.py

+ 6 - 6
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)