1

I'm looking for a client side JavaScript mimetype library similar to Python's mimetypes, or the 'mime' Node module.

I have two related use cases in mind. First is for validating the mimetype in an <input type="file"/> element. 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.

Community
  • 1
  • 1
mjhm
  • 15,731
  • 9
  • 40
  • 55
  • 1
    This resource looks helpful: http://www.html5rocks.com/en/tutorials/file/dndfiles/ – aroth Aug 07 '11 at 00:36
  • It's the right direction. Using the FileReader class works for the first use case when it's available (currently Chrome and Firefox). – mjhm Aug 07 '11 at 01:00

2 Answers2

1

checkout node-mime thay have a browser version

Isaac Weingarten
  • 613
  • 6
  • 10
1

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. 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. Parse result with js and check if it compares with you validation list

Paul Rumkin
  • 5,498
  • 2
  • 20
  • 33
  • Yeah it seems there's nothing in a JS library, or convenient access to the browser's mimetype mapping, except maybe by playing tricks with the FileReader class. As you suggested I ended up rolling my own for my specific use cases. – mjhm Aug 13 '11 at 03:17