So let's assume I have a file stored somewhere and it can be either a jpeg
file or a png
file, what is the way to check what it is?
Should I simply check the extension? Or should I read the file's binary signature? Or how do I do it?
Update: 4/2/2016 to include .JPG validation.
There's a fairly popular hex package Arc that might work for you. Extracted from Arc:
def validate({file, _}) do
~w(.jpg .jpeg .gif .png .JPG) |> Enum.member?(Path.extname(file.file_name))
end
I guess you could extract the Magic number of the file and analyse it. That's fairly simple once you have the format specs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With