简体   繁体   English

是否有客户端 JavaScript mimetype 库?

[英]Is there a client side JavaScript mimetype library?

I'm looking for a client side JavaScript mimetype library similar to Python's mimetypes , or the 'mime' Node module .我正在寻找类似于Python 的 mimetypes'mime' Node module的客户端 JavaScript mimetype 库。

I have two related use cases in mind.我有两个相关的用例。 First is for validating the mimetype in an <input type="file"/> element.首先是验证<input type="file"/>元素中的 mimetype。 The second is for validating a bunch of filenames that come reading the file entries of a ZIP file via js-unzip and Cheeso's unzip utility .第二个是用于验证一堆文件名,这些文件名通过js-unzipCheeso 的 unzip 实用程序读取 ZIP 文件的文件条目。

结帐node-mime有一个浏览器版本

For the first target you can use list of mime types by extention convert in to JSON compress with gz and then use with your script.对于第一个目标,您可以通过扩展使用mime 类型列表,使用 gz 将其转换为 JSON 压缩,然后与您的脚本一起使用。 It's the most simplest way to do this crossbrowser.这是执行此跨浏览器的最简单方法。

The second you can use bash-comands in node, untar archive to tmp and then get mime types of the each file.第二个您可以在节点中使用 bash-comands,将存档解压缩到 tmp,然后获取每个文件的 MIME 类型。 Parse result with js and check if it compares with you validation list用 js 解析结果并检查它是否与您的验证列表进行比较

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM