I’ve got a server script receiving an uploaded file from Javascript.
Client-side, using a File object (from the W3C File API) and code similar to this line:
if (file.type.indexOf("text") == 0) { ... }
one can perform a check of the file type. Apparently, this uses a MIME type (which returns these strings).
In my journeys here through SO, I ventured across this worthy contributor, who maintains that MIME types are useless.
Are MIME types indeed basically useless in a file upload situation, and any type checking should therefore occur server-side?
The contributer is correct. You can’t rely merely on MIME type checking to truly validate a file. It’s only useful for quick lookups. For instance, on the client side, you can check the MIME type of a file before it is sent to the server, just in case the user chose the wrong file type, saving time and bandwidth. Apologies for the liberal use of commas!