Document converter switches to content-based file detection after misnamed uploads
A developer's universal document-to-Markdown converter initially trusted file extensions, which caused a scanned PDF named report.docx to produce garbled output. The fix was to identify formats by magic bytes, using PDF headers, zip signatures, and MP3 markers, with extensions used only as a tiebreaker. The developer also found that EPUB and DOCX files share the zip container, so EPUB detection relies on the mimetype entry and META-INF/container.xml. Plain text with no signature remains the hardest case, and the converter now checks for delimiters and JSON structure before defaulting to text.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in