docx,pptx等正确的mime类型是什么?对于较早的* .doc⽂档,这已⾜够:
header("Content-Type: application/msword");
我应该为新的docx⽂档使⽤哪种mime类型? 还可以⽤于pptx和xlsx⽂档吗?
#1楼
这是⽤于HTTP内容流传输的正确的Microsoft Office MIME类型:
1Extension MIME Type
2.doc      application/msword
3.dot      application/msword
4
5.docx    application/vnd.openxmlformats-officedocument.wordprocessingml.document
6.dotx    application/vnd.plate
7.docm    application/vnd.ms-word.document.macroEnabled.12
8.dotm    application/plate.macroEnabled.12
9
10.xls      application/vnd.ms-excel
11.xlt      application/vnd.ms-excel
12.xla      application/vnd.ms-excel
13
14.xlsx    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
15.xltx    application/vnd.plate
16.xlsm    application/vnd.ms-excel.sheet.macroEnabled.12
17.xltm    application/plate.macroEnabled.12
18.xlam    application/vnd.ms-excel.addin.macroEnabled.12
19.xlsb    application/vnd.ms-excel.sheet.binary.macroEnabled.12
20
21.ppt      application/vnd.ms-powerpoint
22.pot      application/vnd.ms-powerpoint
23.pps      application/vnd.ms-powerpoint
24.ppa      application/vnd.ms-powerpoint
25
26.pptx    application/vnd.openxmlformats-officedocument.presentationml.presentation
27.potx    application/vnd.plate
28.ppsx    application/vnd.openxmlformats-officedocument.presentationml.slideshow
29.ppam    application/vnd.ms-powerpoint.addin.macroEnabled.12
30.pptm    application/vnd.ms-powerpoint.presentation.macroEnabled.12
31.potm    application/plate.macroEnabled.12
32.ppsm    application/vnd.ms-powerpoint.slideshow.macroEnabled.12
33
34.mdb      application/vnd.ms-access
有关更多详细信息,请查看此和此 。
#2楼
另外,如果您使⽤的是.Net v4.5或更⾼版本,请尝试使⽤ (yourFileName)获取MIME类型-⽐硬编码字符串好得多
#3楼
加载.docx⽂件
1    if let htmlFile = Bundle.main.path(forResource: "fileName", ofType: "docx") {
2        let url = URL(fileURLWithPath: htmlFile)
3        do{
4            let data = try Data(contentsOf: url)
5            self.webView.load(data, mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", textEncodingName: "UTF-8"
6        }catch{
7            print("errrr")
8        }
9    }
#4楼
迅捷4
1 func mimeTypeForPath(path: String) -> String {
2        let url = NSURL(fileURLWithPath: path)
3        let pathExtension = url.pathExtension
4
5        if let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension! as NSString, nil)?.takeRetainedValue() {
6            if let mimetype = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() {
7                return mimetype as String
8            }
9        }
10        return "application/octet-stream"
11    }
#5楼
这是JSON格式的(⼏乎)所有⽂件扩展名的MIME的完整信息。 只做⽰例:MIME [“ ppt”],MIME [“ docx”]等
{"x3d": "application/vnd.hzn-3d-crossword", "3gp": "video/3gpp", "3g2": "video/3gpp2", "mseq": "application/vnd.mseq", "pwn": "application/vnd.3m.post-it-notes"
#6楼
这篇⽂章将探讨在各种编程语⾔中获取MIME类型的各种⽅法,并将它们的CONS放在⼀⾏描述中作为标题。 因此,请相应地使⽤它们并为
您⼯作。
例如。 当⽤户可以提供.xls,.xlsx或.xlsm中的任何⼀个,并且您不想编写代码测试扩展名并为每个⽂件提供MIME类型时,以下代码特别
有⽤。 让系统完成这项⼯作。
Python 3
使⽤
1>>> pip install python-magic
2>>> import magic
3>>> magic.from_file("Employee.pdf", mime=True)
4'application/pdf'
使⽤内置的模块-将⽂件名映射到MimeTypes模块
1>>> import mimetypes
2>>> mimetypes.init()
3>>> mimetypes.knownfiles
4['/pes', '/etc/pes', ... ]
5>>> mimetypes.suffix_map['.tgz']
6'.'
7>>> dings_map['.gz']
8'gzip'
9>>> pes_map['.tgz']
10'application/x-tar-gz'
JAVA 7
来源:
取决于操作系统
1@Test
2public void get_JAVA7_mimetype() {
3    Path path = new File("Employee.xlsx").toPath();
4    String mimeType = Files.probeContentType(path);
5
6    assertEquals(mimeType, "application/vnd.ms-excel");
7}
它将使⽤FileTypeDetector实现来探查MIME类型,并调⽤每个实现的probeContentType来解析该类型。 因此,如果实现已知⽂件,则返回内容类型。 但是,如果没有发⽣,则会调⽤系统默认的⽂件类型检测器。
使⽤输⼊流的前⼏个字符进⾏解析
1@Test
2public void getMIMEType_from_Extension(){
3    File file = new File("Employee.xlsx");
4    String mimeType = URLConnection.Name());
5
6    assertEquals(mimeType, "application/vnd.ms-excel");
7}
使⽤MIME类型的内置表
1@Test
2public void getMIMEType_UsingGetFileNameMap(){
3    File file = new File("Employee.xlsx");
4    FileNameMap fileNameMap = FileNameMap();
5    String mimeType = Name());
6
7    assertEquals(mimeType, "image/png");
8}
它返回URLConnection的所有实例使⽤的MIME类型的矩阵,然后将其⽤于解析输⼊⽂件类型。 但是,涉及URLConnection时,此MIME类型矩阵⾮常有限。
默认情况下,该类使⽤JRE_HOME / lib中的content-types.properties⽂件。 但是,我们可以通过使⽤pes.user.table属性指定⽤户特定的表来扩展它:
System.setProperty("pes.user.table","<path-to-file>");
的JavaScript
资料来源: 和
解释使⽤FileReader API提取的幻数
当使⽤javaScript基于⽂件流获取MimeType时,最终结果看起来像这样。 打开嵌⼊式jsFiddle以查看和了解这种⽅法。
presentation什么意思
奖励 :⼤多数MIME类型均可访问它,也可以在getMimetype函数中添加⾃定义Mime类型。 此外,它具有MS Office⽂件Mime类型的完
全⽀持。
在此⽰例中,计算⽂件的MIME类型的步骤为:
1. ⽤户选择⼀个⽂件。
2. 使⽤slice⽅法获取⽂件的前4个字节。
3. 创建⼀个新的FileReader实例
4. 使⽤FileReader读取切成数组缓冲区的4个字节。
5. 由于数组缓冲区只是表⽰⼆进制缓冲区的通⽤⽅法,因此我们需要创建⼀个TypedArray,在这种情况下为Uint8Array。
6. 有了TypedArray,我们可以检索每个字节并将其转换为⼗六进制(通过使⽤toString(16))。
7. 现在,我们有了⼀种⽅法,可以通过读取前四个字节来从⽂件中获取幻数。 最后⼀步是将其映射为
真实的mime类型。
浏览器⽀持(总体上95%以上,在所有现代浏览器中接近100%) :
const uploads = [] const fileSelector = ElementById('file-selector') fileSelector.addEventListener('change', (event) => { console.time('FileOpen'
.result { font-family: Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif; line-height: 20px; font-size: 14px; margin: 10px 0; } .filename  <body> <input type="file" id="file-selector"> <div id="files"></div>
#7楼
如果有⼈希望在C#switch语句中 :
1case "doc": return "application/msword";
2case "dot": return "application/msword";
3case "docx": return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
4case "dotx": return "application/vnd.plate";
5case "docm": return "application/vnd.ms-word.document.macroEnabled.12";
6case "dotm": return "application/plate.macroEnabled.12";
7case "xls": return "application/vnd.ms-excel";
8case "xlt": return "application/vnd.ms-excel";
9case "xla": return "application/vnd.ms-excel";
10case "xlsx": return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
11case "xltx": return "application/vnd.plate";
12case "xlsm": return "application/vnd.ms-excel.sheet.macroEnabled.12";
13case "xltm": return "application/plate.macroEnabled.12";
14case "xlam": return "application/vnd.ms-excel.addin.macroEnabled.12";
15case "xlsb": return "application/vnd.ms-excel.sheet.binary.macroEnabled.12";
16case "ppt": return "application/vnd.ms-powerpoint";
17case "pot": return "application/vnd.ms-powerpoint";
18case "pps": return "application/vnd.ms-powerpoint";
19case "ppa": return "application/vnd.ms-powerpoint";
20case "pptx": return "application/vnd.openxmlformats-officedocument.presentationml.presentation"; 21case "potx": return "application/vnd.plate";
22case "ppsx": return "application/vnd.openxmlformats-officedocument.presentationml.slideshow"; 23case "ppam": return "application/vnd.ms-powerpoint.addin.macroEnabled.12";
24case "pptm": return "application/vnd.ms-powerpoint.presentation.macroEnabled.12";
25case "potm": return "application/plate.macroEnabled.12";
26case "ppsm": return "application/vnd.ms-powerpoint.slideshow.macroEnabled.12";
27case "mdb": return "application/vnd.ms-access";
#8楼
android中的⼀种⼯作⽅法,⽤于填充映射列表mime类型。
1private static void fileMimeTypeMapping() {
2    MIMETYPE_MAPPING.put("3gp", Collections.list("video/3gpp"));
3    MIMETYPE_MAPPING.put("7z", Collections.list("application/x-7z-compressed"));
4    MIMETYPE_MAPPING.put("accdb", Collections.list("application/msaccess"));
5    MIMETYPE_MAPPING.put("ai", Collections.list("application/illustrator"));
6    MIMETYPE_MAPPING.put("apk", Collections.list("application/vnd.android.package-archive"));
7    MIMETYPE_MAPPING.put("arw", Collections.list("image/x-dcraw"));
8    MIMETYPE_MAPPING.put("avi", Collections.list("video/x-msvideo"));
9    MIMETYPE_MAPPING.put("bash", Collections.list("text/x-shellscript"));
10    MIMETYPE_MAPPING.put("bat", Collections.list("application/x-msdos-program"));
11    MIMETYPE_MAPPING.put("blend", Collections.list("application/x-blender"));
12    MIMETYPE_MAPPING.put("bin", Collections.list("application/x-bin"));
13    MIMETYPE_MAPPING.put("bmp", Collections.list("image/bmp"));
14    MIMETYPE_MAPPING.put("bpg", Collections.list("image/bpg"));
15    MIMETYPE_MAPPING.put("bz2", Collections.list("application/x-bzip2"));
16    MIMETYPE_MAPPING.put("cb7", Collections.list("application/x-cbr"));
17    MIMETYPE_MAPPING.put("cba", Collections.list("application/x-cbr"));
18    MIMETYPE_MAPPING.put("cbr", Collections.list("application/x-cbr"));
19    MIMETYPE_MAPPING.put("cbt", Collections.list("application/x-cbr"));
20    MIMETYPE_MAPPING.put("cbtc", Collections.list("application/x-cbr"));
21    MIMETYPE_MAPPING.put("cbz", Collections.list("application/x-cbr"));
22    MIMETYPE_MAPPING.put("cc", Collections.list("text/x-c"));
23    MIMETYPE_MAPPING.put("cdr", Collections.list("application/coreldraw"));
24    MIMETYPE_MAPPING.put("class", Collections.list("application/java"));
25    MIMETYPE_MAPPING.put("cnf", Collections.list("text/plain"));
26    MIMETYPE_MAPPING.put("conf", Collections.list("text/plain"));
27    MIMETYPE_MAPPING.put("cpp", Collections.list("text/x-c++src"));
28    MIMETYPE_MAPPING.put("cr2", Collections.list("image/x-dcraw"));
29    MIMETYPE_MAPPING.put("css", Collections.list("text/css"));
30    MIMETYPE_MAPPING.put("csv", Collections.list("text/csv"));

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。