MIME::Detect - MIME file type identification


  my $mime = MIME::Detect->new();

  for my $file (@ARGV) {
    print sprintf "%s: %s\n", $file, $_->mime_type
        for $mime->mime_types($file);


MIME::Detect->new( ... )

  my $mime = MIME::Detect->new();

Creates a new instance and reads the database distributed with this module.

  my $mime = MIME::Detect->new(
      files => [

$mime->read_database %options

      xml => MIME::Detect::FreeDesktopOrgDB->get_xml,
      files => [

If you want rules in addition to the default database included with the distribution, you can load the rules from another file. Passing in multiple filenames will join the multiple databases. Duplicate file type definitions will not be detected and will be returned as duplicates.

The rules will be sorted according to the priority specified in the database file(s).

By default, the XML database stored alongside MIME::Detect::FreeDesktopOrgDB will be loaded after all custom files have been loaded. To pass in a different fallback database, either pass in a reference to the XML string or the name of a package that has an get_xml subroutine.

To prevent loading the default database, pass undef for the xml key.


    my @types = $mime->mime_types( 'some/file' );
    for( @types ) {
        print $type->mime_type, "\n";

Returns the list of MIME types according to their likelyhood. The first type is the most likely. The returned objects are of type MIME::Detect::Type.


    my $type = $mime->mime_type( 'some/file' );
    print $type->mime_type, "\n"
        if $type;

Returns the most likely type of a file as MIME::Detect::Type. Returns undef if no file type can be determined.

SEE ALSO - the website where the XML file is distributed

File::MimeInfo - module to read your locally installed and converted MIME database

File::LibMagic - if you can install libmagic and the appropriate magic files

File::MMagic - if you have the appropriate magic files

File::MMagic::XS - if you have the appropriate magic files but want more speed

File::Type - inlines its database, unsupported since 2004?

File::Type::WebImages - if you're only interested in determining whether a file is an image or not

MIME::Types - for extension-based detection


The public repository of this module is


The public support forum of this module is


Please report bugs in this module via the RT CPAN bug queue at or via mail to


Max Maischein


Copyright 2015-2016 by Max Maischein


This module is released under the same terms as Perl itself.