[英]Javascript: How to get .tgz MIME type from HTML file input?
I am able to get most file MIME types by checking the file in a HTML file element, however when choosing a .tgz file I do not get a type. 我可以通过检查HTML文件元素中的文件来获取大多数文件MIME类型,但是在选择.tgz文件时我没有获得类型。
Here is a jsfiddle showing the file type when a file is selected from the HTML file input: http://jsfiddle.net/chrisabrams/cTJKf/ 这是一个jsfiddle,显示从HTML文件输入中选择文件时的文件类型: http : //jsfiddle.net/chrisabrams/cTJKf/
According to the spec it's up to the browser to attempt to determine the content-type and if it fails, it should return an empty string. 根据规范 ,浏览器可以尝试确定内容类型,如果失败,则应返回空字符串。
type
类型
The ASCII-encoded string in lower case representing the media type of the
Blob
, expressed as an RFC2046 MIME type [ RFC2046 ].小写的ASCII编码字符串,表示
Blob
的媒体类型,表示为RFC2046 MIME类型[ RFC2046 ]。 On getting, conforming user agents MUST return the MIME type of theBlob
, if it is known.在获取时,符合要求的用户代理必须返回
Blob
的MIME类型(如果已知)。 If conforming user agents cannot determine the media type of theBlob
, they MUST return the empty string.如果符合要求的用户代理无法确定
Blob
的媒体类型,则它们必须返回空字符串。 A string is a valid MIME type if it matches themedia-type
token defined in section 3.7 "Media Types" of RFC 2616 [ HTTP ].如果字符串与RFC 2616 [ HTTP ]的3.7“媒体类型”中定义的
media-type
令牌匹配,则该字符串是有效的MIME类型。
So whatever browser you're using doesn't recognise what a .tgz file is - this could vary both per-browser and also per-operating-system however. 因此,无论您使用什么浏览器都无法识别.tgz文件是什么 - 这可能会因每个浏览器和每个操作系统而异。
I'm using Opera on Linux and it recognises .tgz but - for example - doesn't recognise .xcf 我在Linux上使用Opera,它识别.tgz但是 - 例如 - 不识别.xcf
It's probably browser-dependent. 它可能与浏览器有关。 It works for me in Opera, and gives
application/x-gzip
, but gives nothing in anything else. 它适用于Opera,并提供
application/x-gzip
,但不提供任何其他内容。 You could check it manually with e.target.files[0].value
. 您可以使用
e.target.files[0].value
手动检查它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.