210
Views
1
Comments
How to get right MIME type for .MSG file while uploading file?

When uploading a file,  with extension ".msg" (Outlook E-mail File), the FileUpload UI Element does not show the correct MIME type. In this case, the expected MIME type is "application/vnd.ms-outlook", however the UI element shows the MIME type as "application/octet-stream", which is the generic file type.

The function used to detect MIME type is GetFileMimeType() from MimeType module and for .msg file, it always returns MIME type as "application/octet-stream". Also configured MIME type mapping for .MSG file in IIS server.

2021-03-18 21-03-15
Benjith Sam
 
MVP

Hi Nilam,

I did some search based on the mentioned context and found some of the pointers releated to it. 

  • The file.type attribute is returning blank in case of .msg file upload
  •  The  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

Reference links:

https://stackoverflow.com/questions/43915869/file-with-msg-extension-not-downloading

https://stackoverflow.com/questions/56137532/what-do-you-do-when-angularjs-fileuploader-returns-nothing-for-file-type

https://stackoverflow.com/questions/55687631/which-mime-type-can-i-use-for-msg-file-using-file-object


I could suggest you a work-around i.e. Using JavaScript, you can get the uploaded File type, referring to the file extesnion as mentioned-below.

JavaScript Snippet:

var control = document.querySelector("#" + $parameters.UploadWidgetId + " > input");

if (window.FileReader && window.Blob) {
    // All the File APIs are supported.
    
    control.addEventListener("change", function(event) {
    // When the control has changed, there are new files
    
        var files = control.files;
        var i = 0, fileType = "";
        
        if (files[i].name !== null && files[i].name !== undefined && files[i].name.endsWith(".msg")) {
                fileType = "application/vnd.ms-outlook";
        }
        
         $actions.SetFileInfo(files[i].type || fileType, files[i].size);
    }, false);
} else {
    // File and Blob are not supported
}


See this sample screen UploadWidget_MSG Demo

Refer to the attached .oml file


Hope this helps you!


Kind regards,

Benjith Sam

RWA_Lab_MSG_Demo.oml
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.