Suj*_*ala 5 msg mime-types angular
我试图从之前上传的文件中获取 MIME 类型,但是,它返回“”。是否有任何库或代码可以获取 Angular 中 Outlook 文件的文件类型。例如:对于图像,它显示 'images/png'。请看一看。对于.msg文件扩展名Outlook文件,它显示
但对于.png文件,它显示的文件类型如下
在这个网站上
他们提到不常见的文件扩展名会返回空字符串 如何克服这个问题???请帮助我获取 MIME 类型为 application/vnd.ms-outlook application/octet-stream。
小智 3
我遇到了同样的问题,即浏览器没有为 Outlook-msg-files 返回正确的 mime 类型。而不是显示空字符串application/vnd.ms-outlook的类型属性。File
我使用以下解决方法(通过检查文件扩展名)来解决此问题:
在我的文件上传逻辑中,我测试拖动或选择的文件是否来自任何或更多可接受的 mime 类型。如果有一个文件没有给定 mime-type,那么我会检查文件扩展名。
进一步的验证逻辑,例如,如果给定的文件确实是 Outlook 消息类型,可以使用您喜欢的编程语言在服务器端完成。
let enableOutlookMimetypeDetection: boolean = true;
let acceptRegexString: string = "(image/png)|(application/vnd.ms-outlook)"; // maybe you have to escape the slashes in the regex
let allowOutlookMsgFiles: boolean = enableOutlookMimetypeDetection && acceptRegexString.indexOf("application/vnd.ms-outlook") >= 0;
let acceptRegex: RegExp = new RegExp(acceptRegexString);
for (let i: number = 0; i < files.length; i++) {
if (allowOutlookMsgFiles) {
if (files[i].name !== null && files[i].name !== undefined && files[i].name.endsWith(".msg")) {
console.log("outlook msg-file found");
continue;
}
}
if (!acceptRegex.test(files[i].type)) {
return false;
}
}
return true;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6581 次 |
| 最近记录: |