# perldoc > MojoX::MIME::Types

---
type: CommandReference
command: MojoX::MIME::Types
mode: perldoc
section: 
source: perldoc
---

## Quick Reference

- `MojoX::MIME::Types->new` — create handler (with optional `mime_types` object)
- `$app->types(MojoX::MIME::Types->new)` — set default types in Mojolicious
- `$types->type('foo')` — get MIME type for extension `foo`
- `$types->type(foo => 'text/foo')` — attempt to set type (ignored)
- `$types->detect($accept_header)` — return list of extensions from Accept header
- `$types->mimeTypes` — obtain underlying `MIME::Types` object for advanced queries

## Name

**MojoX::MIME::Types** — MIME Types for Mojolicious

## Synopsis

perl
use MojoX::MIME::Types;

# In Mojolicious application
$app->types(MojoX::MIME::Types->new);

# Basic interface (translated to MIME::Types)
$types->type(foo => 'text/foo');
say $types->type('foo');
## Options

### Constructors

- `new(%options)` — Create a new handler. Options:
  - `mime_types` => `MIME::Types` object (optional, created internally if omitted)
  - `types` => HASH (ignored, accepted for compatibility)

### Attributes

- `mapping(\%table)` — **Avoid.** Returns the internal hash (expensive to construct). Changes via `%table` are ignored. Use `MIME::Types` directly.
- `mimeTypes()` — Returns the internal `MIME::Types` object.

### Actions

- `content_type($controller, \%options)` — Set content type on controller if not already set. Options: `ext` (file extension) or `file` (filename). **Experimental** (Mojo 7.94+).
- `detect($accept, [$prio])` — Return a list of extensions from an HTTP Accept header. Highest priority type first. `$prio` is ignored. Does **not** handle wildcards (`*`). Prefer `MIME::Types::httpAcceptBest()` or `httpAcceptSelect()`.
- `file_type($filename)` — Return MIME type for a filename. **Experimental** (Mojo 7.94+).
- `type($ext, [$type|\@types])` — Get the first MIME type name for extension `$ext`. If `$type` or `@types` are provided, they are ignored and `$self` is returned. Setting types is not supported (use `MIME::Types` for a complete database).

## Examples

**Using with Mojolicious (full app)**

perl
package MyApp;
use Mojo::Base 'Mojolicious';

sub startup {
    my $self = shift;
    $self->types(MojoX::MIME::Types->new);
}
**Using with custom `MIME::Types` options**

perl
my $mt    = MIME::Types->new(%opts);
my $types = MojoX::MIME::Types->new(mime_types => $mt);
$self->types($types);
**Accessing the underlying `MIME::Types` object**

perl
my $mt   = $app->types->mimeTypes;
my $mime = $mt->mimeTypeOf('file.html');
**Using with Mojolicious::Lite**

perl
app->types(MojoX::MIME::Types->new);
my $types = app->types;
## See Also

- [Mojo::Base](http://localhost/phpMan.php/perldoc/Mojo%3A%3ABase/markdown)
- [Mojolicious::Types](http://localhost/phpMan.php/perldoc/Mojolicious%3A%3ATypes/markdown) — the original (less complete) MIME type handler
- [MIME::Types](http://localhost/phpMan.php/perldoc/MIME%3A%3ATypes/markdown) — the full MIME type database
- [MIME::Type](http://localhost/phpMan.php/perldoc/MIME%3A%3AType/markdown) — single MIME type object
- [MIME::Types::httpAcceptBest](http://localhost/phpMan.php/perldoc/MIME%3A%3ATypes%3A%3AhttpAcceptBest/markdown) — recommended Accept header parser
- [MIME::Types::httpAcceptSelect](http://localhost/phpMan.php/perldoc/MIME%3A%3ATypes%3A%3AhttpAcceptSelect/markdown) — negotiate best type from Accept header

## Exit Codes

Not documented.