简体   繁体   English

Javascript:如何从HTML文件输入获取.tgz MIME类型?

[英]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 the Blob , if it is known. 在获取时,符合要求的用户代理必须返回Blob的MIME类型(如果已知)。 If conforming user agents cannot determine the media type of the Blob , they MUST return the empty string. 如果符合要求的用户代理无法确定Blob的媒体类型,则它们必须返回空字符串。 A string is a valid MIME type if it matches the media-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.

相关问题 如何在javascript中获取html输入文件类型属性? - How to get html input file type properties in javascript? jQuery或JavaScript:获取客户端文件的MIME类型 - jQuery or JavaScript: get MIME type of client file 如何使用JavaScript或JQuery从input type = file html元素获取文件名? - How to get the filename from input type=file html element using JavaScript or JQuery? Javascript - 如何从输入类型=“文件”中获取实际文件 - Javascript - How to get the actual file from an input type=“file” 如何从MIME类型获取媒体类型? - How to get a media type from a MIME type? 如何使用javascript从输入类型文件中获取字节数组 - How to get byte array from input type file using javascript 如何从中获取文件 <input type='file' …/> (间接)与javascript - how to get files from <input type='file' …/> (Indirect) with javascript Chrome for Android上的Html文件输入缺少扩展名和mime类型 - Html File Input on Chrome for Android missing extension and mime type Jade/pug 将 javascript 文件的 MIME 类型设置为 text/html - Jade/pug setting MIME type of javascript file to text/html 脚本来自<url>即使其 MIME 类型(“text/html”)不是有效的 JavaScript MIME 类型,也已加载 - The script from <url> was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM