File Type Support#
MinerU accepts a fixed set of file types defined as whitelisted suffix lists in mineru/cli/common.py:
| Category | Formats |
|---|---|
pdf | |
| Images | png, jpeg, jp2, webp, gif, bmp, jpg, tiff |
| Office | docx, pptx, xlsx |
These three lists are combined into the constant SUPPORTED_UPLOAD_SUFFIXES used by the FastAPI layer for upload validation.
File Type Detection#
Detection uses a three-stage pipeline implemented in mineru/utils/guess_suffix_or_lang.py:
-
OOXML structure inspection — For Office documents, MinerU parses the ZIP package structure (reading
_rels/.relsand[Content_Types].xml) to identify docx/pptx/xlsx by their main content-type relationships. This runs before Magika to avoid false positives from embedded objects . -
Magika detection — If OOXML inspection returns nothing, Magika is invoked. A global
Magika()instance is initialized at module load time . Two entry points exist:guess_suffix_by_bytes(file_bytes, file_path=None)— used when raw bytes are available (e.g. in-memory processing)guess_suffix_by_path(file_path)— used for on-disk files (e.g. during upload validation)
-
PDF signature fallback — When Magika returns
"ai"or"html"for a.pdf-extension file, the code reads the first 4 bytes and corrects the label to"pdf"if the%PDFmagic bytes are present . This handles edge cases where Magika misclassifies valid PDFs.
Filtering Behavior by Context#
CLI / collect_input_documents: When processing a directory, the CLI silently skips any file whose detected suffix is not in pdf_suffixes + image_suffixes + office_suffixes . No error or warning is emitted for skipped files; they are simply excluded from the collected document list.
FastAPI upload (save_upload_files): Unsupported file types are explicitly rejected. After writing the upload to disk, guess_suffix_by_path() is called; if the result is not in SUPPORTED_UPLOAD_SUFFIXES, the file is deleted and an HTTP 400 is raised with "Unsupported file type: {suffix}" .
read_fn (used in direct API calls): Raises a plain Exception("Unknown file suffix: {suffix}") for any suffix not in the whitelist .
Office vs. PDF/Image Pipeline Split#
Office files (docx, pptx, xlsx) are routed to a separate _process_office_doc path inside do_parse(), which dispatches to format-specific analyzers (office_docx_analyze, office_pptx_analyze, office_xlsx_analyze). After office files are processed, they are removed from the remaining list; only then does the PDF/image pipeline run . Image files are converted to PDF bytes before PDF processing begins via images_bytes_to_pdf_bytes .