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

查看:28
本文介绍了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 类型.任意内容数据的 MIME 类型在用于传输数据的 Internet 协议(例如 HTTP、SMTP、RTP 等)的标头中描述.

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天全站免登陆