Flex SDK 3.5 - Check mimetype file

Is there a way to get the mimetype file in Flex SDK 3.5 without using its extension?

I need to check if an uploaded file is of a specific type. This is for images or documents (PDF, ODT, etc.).

All solutions I have found check its extension. What if I rename the .odt file as .jpg? Then I can load it as an image ...

I must add, we are using a desktop AIR client and a Java EE server. File validation is solved on the Java side, but the idea is not to go to the server to validate the file, so if it is invalid, there is no network traffic at all.

+2


a source to share


2 answers


Not really. The files do not have a built-in MIME type. The arbitrary data type of the MIME content is described in the header of the Internet protocol used to transport the data (such as HTTP, SMTP, RTP, etc.).

The only other solution I could think of is a trial and error process, in which you have an assumption about the type of file you are dealing with and you test that hypothesis by actually opening the file (in your code) and testing for success. But this is ugly.



Steav, your solution is just considering the response header, which might not be set correctly.

+3


a source


The easiest way is to use php if possible:



$fileinfo['content-type'];

      

-1


a source







All Articles