Flex SDK 3.5 - 检查文件mimetype [英] Flex SDK 3.5 - Check file mimetype

查看:243
本文介绍了Flex SDK 3.5 - 检查文件mimetype的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在Flex SDK 3.5中获取文件的mimetype而不使用其扩展名?

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

我需要验证上传的文件是否属于某种类型。这适用于图像或文档(PDF,ODT等)

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

我发现的所有解决方案都是通过检查其扩展名来实现的。如果我将.odt文件重命名为.jpg怎么办?然后我可以将其作为图像上传...

All the solutions I've found are by checking its extension. What if I rename a .odt file as a .jpg? Then I can upload it as an image...

我应该添加,我们使用 AIR桌面客户端和Java EE服务器。文件检查是在Java端解决的,但想法不是去服务器,验证文件,如果它无效,根本就没有网络流量。

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.

推荐答案

不是真的。文件没有固有的MIME类型。在用于传输数据的因特网协议的头部(例如HTTP,SMTP,RTP等)中描述了任意内容数据的MIME类型。

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,你的解决方案只是查看响应标题,可能没有正确设置。

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

这篇关于Flex SDK 3.5 - 检查文件mimetype的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆