开发者

Is there any javascript library that calculate content-type based on file extension?

开发者 https://www.devze.com 2023-02-11 04:48 出处:网络
Is there any javascript library that calcu开发者_运维百科late content-type based on file extension?Couldn\'t find any after a little searching but you could create your own by finding a preferred mapp

Is there any javascript library that calcu开发者_运维百科late content-type based on file extension?


Couldn't find any after a little searching but you could create your own by finding a preferred mapping and encoding them in an external JavaScript library like so:

// mime-types.js
mimeTypes = {
  'byExtension': {
    '': 'application/octet-stream',
    'ai': 'application/postscript',
    'aif': 'audio/x-aiff'
    //...
  },
  'byType': {
    'application/octet-stream': ['', '*', 'bin', 'class', 'exe' /*, ...*/],
    'application/pdf': ['pdf']
    //...
  }
}

A good text editor with macros or a simple shell script could do the majority of the encoding for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消