Skip to content

Instantly share code, notes, and snippets.

@sabit990928
Created August 6, 2021 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sabit990928/e29319b7dcaebc9f47a168b3d68748c1 to your computer and use it in GitHub Desktop.
Save sabit990928/e29319b7dcaebc9f47a168b3d68748c1 to your computer and use it in GitHub Desktop.
Validation waffle
def validate({file, _}) do
{:ok, info} = File.stat(file.path)
if info.size < 2_000_000 do
file_extension = file.file_name |> Path.extname() |> String.downcase()
case Enum.member?(~w(.jpg .jpeg .gif .png), file_extension) do
true -> :ok
false -> {:error, "file type is invalid"}
end
else
{:error, "file size is too large"}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment