Skip to content

Instantly share code, notes, and snippets.

View sabit990928's full-sized avatar
🎯
Focusing

Sabit Rakhim sabit990928

🎯
Focusing
View GitHub Profile
@sabit990928
sabit990928 / validate.ex
Created August 6, 2021 08:42
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