The disk refused the content. Send other content.
A plugin, the adapter or the storage refuses content that breaks the disk's rules, and :reason says which rule, in
the form its source documents. Fil.Plugin.Validation returns it for a file that's too large or of a type the disk
doesn't take, and Fil.Plugin.Thumbnails for a file that isn't an image ({:not_an_image, message}). Adapters
return it for content over the storage's size limit, such as S3's "EntityTooLarge", and with
reason: :too_many_parts for a stream that needs more parts than the storage allows. Fil.LiveView returns it with
reason: :extension for an upload whose path has an extension the upload doesn't accept, before anything is
written, and with reason: :too_large for a direct upload's file over the upload's max_file_size.
Raised while the content of a write is read (from a function given to Fil.Op.scan_content/4, say), it's the
write's result, and nothing is written. Fil.Plug answers an upload that fails with it with a 413 for
{:too_large, _}, a 415 for {:content_type, _}, {:content_type_mismatch, _, _} and {:extension, _}, and a
422 for anything else, without the reason.
iex> disk =
...> Fil.disk(adapter: Fil.Adapter.Memory)
...> |> Fil.attach(:no_html, fn op, next, _opts ->
...> op
...> |> Fil.Op.scan_content(nil, fn chunk, acc ->
...> if chunk =~ "<script", do: raise(%Fil.InvalidContentError{reason: :html}), else: acc
...> end)
...> |> next.()
...> end)
iex> {:error, error} = Fil.write(disk, "notes.txt", "<script>alert(1)</script>")
iex> Exception.message(error)
~s|could not write "notes.txt" on #Fil.Disk<memory>: the content was rejected (:html)|
iex> Fil.exists?(disk, "notes.txt")
false
Summary
Types
@type t() :: %Fil.InvalidContentError{ __exception__: term(), disk: Fil.Disk.t() | nil, op: Fil.Op.name() | nil, path: String.t() | nil, reason: term() }