1

I am accepting new files like this:

<input type="file" accept="image/x-png,image/gif,image/jpeg" required>

I do not currently have a converter in place, so webp images that are uploaded will not work when displayed on ios or Safari. To combat this, I added the jpg, png, and gif "accept" attribute.

However, if a user renames a webp as one of the accepted files, my file picker won't detect the mislabel, but it will still be a webp and therefore broken as described.

Is there a better way to check the file type using html or javascript?

2
  • 1
    Possible duplicate of How to check file MIME type with javascript before upload? (Hopefully you can extract a usable answer, it seems it's very similar.) Commented Apr 20, 2019 at 23:04
  • Yes, the answer provided by @lmiguelmh worked for me. I did not know to refer to this underlying file type as the MIME type. Thanks! Commented Apr 21, 2019 at 0:10

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.