Is there any javascript library that calculate content-type based on file extension?
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.
精彩评论