libb.magic_mime_from_buffer

magic_mime_from_buffer(buffer)[source]

Detect mimetype from a file’s bytes using the magic library.

OOXML (docx/xlsx/pptx) and ODF documents that libmagic reports as the generic application/zip are refined to their precise type by inspecting the archive – pass the whole file, not just a header, for that refinement to apply.

Parameters:

buffer (bytes) – File bytes (whole file recommended).

Returns:

The detected mimetype.

Return type:

str