TL;DR: There’s no way at the moment.
Long answer: Yes, it is possible, but not with the current tools.
Most detection solutions for MIME Type
are based on the file extension - Filetype.JS, for example, does just that.
To determine the content-type
correct, you need to open the file and investigate by headers of known formats, also known as Magic Bytes (or Magic Numbers).
Some examples (source):
Executáveis Mnemônico Assinatura (bytes)
DOS Executable "MZ" 0x4D 0x5A
PE32 Executable "MZ"...."PE.." 0x4D 0x5A ... 0x50 0x45 0x00 0x00
Mach-O Executable (32 bit) "FEEDFACE" 0xFE 0xED 0xFA 0xCE
Mach-O Executable (64 bit) "FEEDFACF" 0xFE 0xED 0xFA 0xCF
ELF Executable ".ELF" 0x7F 0x45 0x4C 0x46
Protocolos de compressão Mnemônico Assinatura (bytes)
Zip Archives "PK.." 0x50 0x4B 0x03 0x04
Rar Archives "Rar!...." 0x52 0x61 0x72 0x21 0x1A 0x07 0x01 0x00
Ogg Container "OggS" 0x4F 0x67 0x67 0x53
Matroska/EBML Container N/A 0x45 0x1A 0xA3 0xDF
Image File Formats Mnemônico Assinatura (bytes)
PNG Image ".PNG...." 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A
BMP Image "BM" 0x42 0x4D
GIF Image "GIF87a" 0x47 0x49 0x46 0x38 0x37 0x61
GIF Image "GIF89a" 0x47 0x49 0x46 0x38 0x39 0x61
(More information via Wikipedia.)
One of the new possibilities offered by the HTML5 specification is the File API, it is possible to open files and perform look-ups by such bytes. Still you will encounter some problems:
Some formats do not have Magic bytes, it being impossible to distinguish their content without some kind of Parsing: for example, Javascript versus HTML versus plain text files.
Some formats have repeatable bytes Magic.
This would be possible by checking the MIME type file, but as far as I know Javascript can not get the MIME type, you would have to check with a language server-side.
– Kazzkiq
@Kazzkiq, I know php does this, but the problem is that I would not like to upload to the server.
– Rogers Corrêa