【问题标题】:which mime type can I use for .MSG file using FILE object我可以使用 FILE 对象将哪种 mime 类型用于 .MSG 文件
【发布时间】:2019-09-05 08:15:26
【问题描述】:

我试图从之前上传的 FILE 中获取 MIME 类型,但它返回 ''。是否有任何库或代码用于在 Angular 中获取 Outlook 文件的文件类型。例如:对于显示“images/png”的图像。请看一看。 .msg 文件扩展名 outlook 文件显示

但是对于.png文件,它显示文件类型如下

在这个site

他们提到不常见的文件扩展名会返回一个空字符串 如何克服这个问题???请帮助我获取 MIME 类型为 application/vnd.ms-outlook 应用程序/八位字节流。

【问题讨论】:

  • 您是在问 MIME 类型应该是什么,或者如何以编程方式确定它?
  • “我尝试过……”:然后提供minimal reproducible example

标签: angular mime-types msg


【解决方案1】:

我遇到了同样的问题/问题,即浏览器没有为 outlook-msg-files 返回正确的 mime-type。 File 的类型属性不是application/vnd.ms-outlook,而是显示一个空字符串

我使用以下解决方法(通过检查文件扩展名)来解决这个问题:

在我的文件上传逻辑中,我测试拖动或选择的文件是否来自任何或更多可接受的 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;

【讨论】:

    猜你喜欢
    • 2017-05-18
    • 2013-02-13
    • 2012-05-28
    • 2011-10-10
    • 2011-09-28
    • 2015-04-21
    • 2015-09-13
    相关资源
    最近更新 更多