mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
image upload mime validation - shows you what it thinks the mime type is (#79)
This commit is contained in:
parent
603c8d4867
commit
ae6640e9d3
3 changed files with 7 additions and 2 deletions
|
@ -155,7 +155,8 @@ defmodule Philomena.Images.Image do
|
|||
|> validate_length(:image_name, max: 255, count: :bytes)
|
||||
|> validate_inclusion(
|
||||
:image_mime_type,
|
||||
~W(image/gif image/jpeg image/png image/svg+xml video/webm)
|
||||
~W(image/gif image/jpeg image/png image/svg+xml video/webm),
|
||||
message: "(#{attrs["image_mime_type"]}) is invalid"
|
||||
)
|
||||
|> unsafe_validate_unique([:image_orig_sha512_hash], Repo)
|
||||
end
|
||||
|
|
|
@ -33,5 +33,5 @@ defmodule Philomena.Mime do
|
|||
when mime in ~W(image/gif image/jpeg image/png image/svg+xml video/webm),
|
||||
do: {:ok, mime}
|
||||
|
||||
def true_mime(_mime), do: :error
|
||||
def true_mime(mime), do: {:unsupported_mime, mime}
|
||||
end
|
||||
|
|
|
@ -43,6 +43,10 @@ defmodule Philomena.Uploader do
|
|||
|
||||
changeset_fn.(model_or_changeset, attributes)
|
||||
else
|
||||
{:unsupported_mime, mime} ->
|
||||
attributes = prefix_attributes(%{"mime_type" => mime}, field_name)
|
||||
changeset_fn.(model_or_changeset, attributes)
|
||||
|
||||
_error ->
|
||||
changeset_fn.(model_or_changeset, %{})
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue