2
votes

I have tried to get MIME-type from the FILE which is uploaded earlier but, it is return ''. Is there any library or code for getting file-type of the outlook files in Angular. ex: for images it is showing 'images/png'. please have a look. for .msg file extension outlook file it is showing

enter image description here

But for .png file, it is showing file type as below

enter image description here

in this site

they mentioned Uncommon file extensions would return an empty string How to overcome this issue??? Please help me out to get the MIME type as application/vnd.ms-outlook application/octet-stream.

1
Are you asking what the MIME type should be, or how to determine it programmatically?Quentin
"I have tried to…": Then provide a minimal reproducible example.Quentin

1 Answers

2
votes

I came across the same issue/problem that the browser doesn't return correct mime-type for outlook-msg-files. Instead of application/vnd.ms-outlook the type-property of File shows an empty string.

I used the following workaround (by checking the file-extension) to overcome this problem:

In my file-upload-logic, I test the dragged or selected file(s) if they are from any or more accepted mime-types. If there is a file without given mime-type, then I check the file-extension.

Further validation logic, e.g. if the given file is really of outlook-message-type, can be done on the server-side with your prefered programming language.

    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;