mime.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. package oss
  2. import (
  3. "mime"
  4. "path"
  5. "strings"
  6. )
  7. var extToMimeType = map[string]string{
  8. ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  9. ".xltx": "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
  10. ".potx": "application/vnd.openxmlformats-officedocument.presentationml.template",
  11. ".ppsx": "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
  12. ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
  13. ".sldx": "application/vnd.openxmlformats-officedocument.presentationml.slide",
  14. ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
  15. ".dotx": "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
  16. ".xlam": "application/vnd.ms-excel.addin.macroEnabled.12",
  17. ".xlsb": "application/vnd.ms-excel.sheet.binary.macroEnabled.12",
  18. ".apk": "application/vnd.android.package-archive",
  19. ".hqx": "application/mac-binhex40",
  20. ".cpt": "application/mac-compactpro",
  21. ".doc": "application/msword",
  22. ".ogg": "application/ogg",
  23. ".pdf": "application/pdf",
  24. ".rtf": "text/rtf",
  25. ".mif": "application/vnd.mif",
  26. ".xls": "application/vnd.ms-excel",
  27. ".ppt": "application/vnd.ms-powerpoint",
  28. ".odc": "application/vnd.oasis.opendocument.chart",
  29. ".odb": "application/vnd.oasis.opendocument.database",
  30. ".odf": "application/vnd.oasis.opendocument.formula",
  31. ".odg": "application/vnd.oasis.opendocument.graphics",
  32. ".otg": "application/vnd.oasis.opendocument.graphics-template",
  33. ".odi": "application/vnd.oasis.opendocument.image",
  34. ".odp": "application/vnd.oasis.opendocument.presentation",
  35. ".otp": "application/vnd.oasis.opendocument.presentation-template",
  36. ".ods": "application/vnd.oasis.opendocument.spreadsheet",
  37. ".ots": "application/vnd.oasis.opendocument.spreadsheet-template",
  38. ".odt": "application/vnd.oasis.opendocument.text",
  39. ".odm": "application/vnd.oasis.opendocument.text-master",
  40. ".ott": "application/vnd.oasis.opendocument.text-template",
  41. ".oth": "application/vnd.oasis.opendocument.text-web",
  42. ".sxw": "application/vnd.sun.xml.writer",
  43. ".stw": "application/vnd.sun.xml.writer.template",
  44. ".sxc": "application/vnd.sun.xml.calc",
  45. ".stc": "application/vnd.sun.xml.calc.template",
  46. ".sxd": "application/vnd.sun.xml.draw",
  47. ".std": "application/vnd.sun.xml.draw.template",
  48. ".sxi": "application/vnd.sun.xml.impress",
  49. ".sti": "application/vnd.sun.xml.impress.template",
  50. ".sxg": "application/vnd.sun.xml.writer.global",
  51. ".sxm": "application/vnd.sun.xml.math",
  52. ".sis": "application/vnd.symbian.install",
  53. ".wbxml": "application/vnd.wap.wbxml",
  54. ".wmlc": "application/vnd.wap.wmlc",
  55. ".wmlsc": "application/vnd.wap.wmlscriptc",
  56. ".bcpio": "application/x-bcpio",
  57. ".torrent": "application/x-bittorrent",
  58. ".bz2": "application/x-bzip2",
  59. ".vcd": "application/x-cdlink",
  60. ".pgn": "application/x-chess-pgn",
  61. ".cpio": "application/x-cpio",
  62. ".csh": "application/x-csh",
  63. ".dvi": "application/x-dvi",
  64. ".spl": "application/x-futuresplash",
  65. ".gtar": "application/x-gtar",
  66. ".hdf": "application/x-hdf",
  67. ".jar": "application/x-java-archive",
  68. ".jnlp": "application/x-java-jnlp-file",
  69. ".js": "application/x-javascript",
  70. ".ksp": "application/x-kspread",
  71. ".chrt": "application/x-kchart",
  72. ".kil": "application/x-killustrator",
  73. ".latex": "application/x-latex",
  74. ".rpm": "application/x-rpm",
  75. ".sh": "application/x-sh",
  76. ".shar": "application/x-shar",
  77. ".swf": "application/x-shockwave-flash",
  78. ".sit": "application/x-stuffit",
  79. ".sv4cpio": "application/x-sv4cpio",
  80. ".sv4crc": "application/x-sv4crc",
  81. ".tar": "application/x-tar",
  82. ".tcl": "application/x-tcl",
  83. ".tex": "application/x-tex",
  84. ".man": "application/x-troff-man",
  85. ".me": "application/x-troff-me",
  86. ".ms": "application/x-troff-ms",
  87. ".ustar": "application/x-ustar",
  88. ".src": "application/x-wais-source",
  89. ".zip": "application/zip",
  90. ".m3u": "audio/x-mpegurl",
  91. ".ra": "audio/x-pn-realaudio",
  92. ".wav": "audio/x-wav",
  93. ".wma": "audio/x-ms-wma",
  94. ".wax": "audio/x-ms-wax",
  95. ".pdb": "chemical/x-pdb",
  96. ".xyz": "chemical/x-xyz",
  97. ".bmp": "image/bmp",
  98. ".gif": "image/gif",
  99. ".ief": "image/ief",
  100. ".png": "image/png",
  101. ".wbmp": "image/vnd.wap.wbmp",
  102. ".ras": "image/x-cmu-raster",
  103. ".pnm": "image/x-portable-anymap",
  104. ".pbm": "image/x-portable-bitmap",
  105. ".pgm": "image/x-portable-graymap",
  106. ".ppm": "image/x-portable-pixmap",
  107. ".rgb": "image/x-rgb",
  108. ".xbm": "image/x-xbitmap",
  109. ".xpm": "image/x-xpixmap",
  110. ".xwd": "image/x-xwindowdump",
  111. ".css": "text/css",
  112. ".rtx": "text/richtext",
  113. ".tsv": "text/tab-separated-values",
  114. ".jad": "text/vnd.sun.j2me.app-descriptor",
  115. ".wml": "text/vnd.wap.wml",
  116. ".wmls": "text/vnd.wap.wmlscript",
  117. ".etx": "text/x-setext",
  118. ".mxu": "video/vnd.mpegurl",
  119. ".flv": "video/x-flv",
  120. ".wm": "video/x-ms-wm",
  121. ".wmv": "video/x-ms-wmv",
  122. ".wmx": "video/x-ms-wmx",
  123. ".wvx": "video/x-ms-wvx",
  124. ".avi": "video/x-msvideo",
  125. ".movie": "video/x-sgi-movie",
  126. ".ice": "x-conference/x-cooltalk",
  127. ".3gp": "video/3gpp",
  128. ".ai": "application/postscript",
  129. ".aif": "audio/x-aiff",
  130. ".aifc": "audio/x-aiff",
  131. ".aiff": "audio/x-aiff",
  132. ".asc": "text/plain",
  133. ".atom": "application/atom+xml",
  134. ".au": "audio/basic",
  135. ".bin": "application/octet-stream",
  136. ".cdf": "application/x-netcdf",
  137. ".cgm": "image/cgm",
  138. ".class": "application/octet-stream",
  139. ".dcr": "application/x-director",
  140. ".dif": "video/x-dv",
  141. ".dir": "application/x-director",
  142. ".djv": "image/vnd.djvu",
  143. ".djvu": "image/vnd.djvu",
  144. ".dll": "application/octet-stream",
  145. ".dmg": "application/octet-stream",
  146. ".dms": "application/octet-stream",
  147. ".dtd": "application/xml-dtd",
  148. ".dv": "video/x-dv",
  149. ".dxr": "application/x-director",
  150. ".eps": "application/postscript",
  151. ".exe": "application/octet-stream",
  152. ".ez": "application/andrew-inset",
  153. ".gram": "application/srgs",
  154. ".grxml": "application/srgs+xml",
  155. ".gz": "application/x-gzip",
  156. ".htm": "text/html",
  157. ".html": "text/html",
  158. ".ico": "image/x-icon",
  159. ".ics": "text/calendar",
  160. ".ifb": "text/calendar",
  161. ".iges": "model/iges",
  162. ".igs": "model/iges",
  163. ".jp2": "image/jp2",
  164. ".jpe": "image/jpeg",
  165. ".jpeg": "image/jpeg",
  166. ".jpg": "image/jpeg",
  167. ".kar": "audio/midi",
  168. ".lha": "application/octet-stream",
  169. ".lzh": "application/octet-stream",
  170. ".m4a": "audio/mp4a-latm",
  171. ".m4p": "audio/mp4a-latm",
  172. ".m4u": "video/vnd.mpegurl",
  173. ".m4v": "video/x-m4v",
  174. ".mac": "image/x-macpaint",
  175. ".mathml": "application/mathml+xml",
  176. ".mesh": "model/mesh",
  177. ".mid": "audio/midi",
  178. ".midi": "audio/midi",
  179. ".mov": "video/quicktime",
  180. ".mp2": "audio/mpeg",
  181. ".mp3": "audio/mpeg",
  182. ".mp4": "video/mp4",
  183. ".mpe": "video/mpeg",
  184. ".mpeg": "video/mpeg",
  185. ".mpg": "video/mpeg",
  186. ".mpga": "audio/mpeg",
  187. ".msh": "model/mesh",
  188. ".nc": "application/x-netcdf",
  189. ".oda": "application/oda",
  190. ".ogv": "video/ogv",
  191. ".pct": "image/pict",
  192. ".pic": "image/pict",
  193. ".pict": "image/pict",
  194. ".pnt": "image/x-macpaint",
  195. ".pntg": "image/x-macpaint",
  196. ".ps": "application/postscript",
  197. ".qt": "video/quicktime",
  198. ".qti": "image/x-quicktime",
  199. ".qtif": "image/x-quicktime",
  200. ".ram": "audio/x-pn-realaudio",
  201. ".rdf": "application/rdf+xml",
  202. ".rm": "application/vnd.rn-realmedia",
  203. ".roff": "application/x-troff",
  204. ".sgm": "text/sgml",
  205. ".sgml": "text/sgml",
  206. ".silo": "model/mesh",
  207. ".skd": "application/x-koan",
  208. ".skm": "application/x-koan",
  209. ".skp": "application/x-koan",
  210. ".skt": "application/x-koan",
  211. ".smi": "application/smil",
  212. ".smil": "application/smil",
  213. ".snd": "audio/basic",
  214. ".so": "application/octet-stream",
  215. ".svg": "image/svg+xml",
  216. ".t": "application/x-troff",
  217. ".texi": "application/x-texinfo",
  218. ".texinfo": "application/x-texinfo",
  219. ".tif": "image/tiff",
  220. ".tiff": "image/tiff",
  221. ".tr": "application/x-troff",
  222. ".txt": "text/plain",
  223. ".vrml": "model/vrml",
  224. ".vxml": "application/voicexml+xml",
  225. ".webm": "video/webm",
  226. ".wrl": "model/vrml",
  227. ".xht": "application/xhtml+xml",
  228. ".xhtml": "application/xhtml+xml",
  229. ".xml": "application/xml",
  230. ".xsl": "application/xml",
  231. ".xslt": "application/xslt+xml",
  232. ".xul": "application/vnd.mozilla.xul+xml",
  233. ".webp": "image/webp",
  234. }
  235. // TypeByExtension returns the MIME type associated with the file extension ext.
  236. // gets the file's MIME type for HTTP header Content-Type
  237. func TypeByExtension(filePath string) string {
  238. typ := mime.TypeByExtension(path.Ext(filePath))
  239. if typ == "" {
  240. typ = extToMimeType[strings.ToLower(path.Ext(filePath))]
  241. }
  242. return typ
  243. }