# `Fil.Plugin.ContentType`
[🔗](https://github.com/pehbehbeh/fil/blob/v0.1.0/lib/fil/plugin/content_type.ex#L1)

Sets the content type of a write from the file extension.

    disk =
      Fil.disk(adapter: Fil.Adapter.S3, bucket: "docs")
      |> Fil.Plugin.ContentType.attach()

    Fil.write(disk, "reports/q3.pdf", pdf)
    # stored as application/pdf

A `content_type:` given to the call wins. Only writes are changed, including the write half of a copy across disks. A
copy within one disk keeps the source's content type. The local filesystem stores no content type, so this plugin is
only useful on object stores.

The extension is looked up with [MIME](https://hex.pm/packages/mime), which you can extend with your own types in your
config (see its docs).

It's also the smallest complete example of a plugin module (see the [Plugins guide](plugins.md)): a public callback
that validates its options, handles one operation and passes the rest on, and an `attach/2` for piping.

## Options

* `:default` (`t:String.t/0`) - The content type for a path whose extension [MIME](https://hex.pm/packages/mime) doesn't know. The default value is `"application/octet-stream"`.

# `attach`

```elixir
@spec attach(
  Fil.Disk.t(),
  keyword()
) :: Fil.Disk.t()
```

Attaches the plugin to `disk` under the name `Fil.Plugin.ContentType`.

The same as `plugins: [{Fil.Plugin.ContentType, :call, opts}]` in `Fil.disk/1`, except that the options are validated
here instead of on the first write.

