Created
August 6, 2021 08:42
-
-
Save sabit990928/e29319b7dcaebc9f47a168b3d68748c1 to your computer and use it in GitHub Desktop.
Validation waffle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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