Fil.Plugin.ContentType (Fil v0.1.0)

Copy Markdown View Source

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, 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): a public callback that validates its options, handles one operation and passes the rest on, and an attach/2 for piping.

Options

  • :default (String.t/0) - The content type for a path whose extension MIME doesn't know. The default value is "application/octet-stream".

Summary

Functions

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

Functions

attach(disk, opts \\ [])

@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.