开发者

Flex SDK 3.5 - Check file mimetype

开发者 https://www.devze.com 2022-12-27 04:53 出处:网络
Is there a way to get a file\'s mimetype in Flex SDK 3.5 without using its extension? I need to validate if an uploaded file is of a certain kind. This is for images, or documents (PDF, ODT, etc.)

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

I need to validate if an uploaded file is of a certain kind. This is for images, or documents (PDF, ODT, etc.)

All the solutions I've found are by ch开发者_开发知识库ecking its extension. What if I rename a .odt file as a .jpg? Then I can upload it as an image...

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


Not really. Files do not have an inherent MIME type. The MIME type of arbitrary content data 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 off the top of my head is using a trial-and-error process where you have a guess at the file type you're dealing with, and you test that guess by actually opening the file (in your code) and testing for success. But that's ugly.

Steav, your solution just looks at the response header, which might not be set correctly.


Easiest way would be using php, if possible:

$fileinfo['content-type'];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号