Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE 11 and IE Edge get file.type failed

"change .btn-file :file"       : "getfileinfo",

getfileinfo: function(e){

    var fileInput = document.getElementById('fileupload');
    var file = fileInput.files[0];

    if(!file || (file.type != 'text/plain' && file.type != 'text/csv' && file.type != 'application/csv' && file.type != 'application/vnd.ms-excel' && file.type != 'text/csv')){
        $('.alert-file').show();
        $('.alert-file').delay(4000).fadeOut('slow');
        return false;
    }
    var reader = new FileReader();

    reader.onload = function(e) {
        $('#fileData').val(reader.result);
        $('#fileName').val(file.name); 

    };
    reader.readAsDataURL(file);

}

file.type is null if i used in IE11 and IE Edge. All other browser working fine.

Can someone help me on this ?

like image 653
Gopi Avatar asked Sep 29 '15 16:09

Gopi


1 Answers

Test case

<input type="file" onchange="document.body.innerText = this.files[0].type" />

returns MIME for SVG, PNG, ZIP, but returns "" for PDF

Reproduced on IE11 under Windows 8.1 Pro x64

Version: 11.0.9600.18053
Update Versions: 11.0.24 (KB3093983)

Bug already reported and closed with "could not reproduce" https://connect.microsoft.com/IE/Feedback/Details/2009205. It mentions why IE team can not reproduce:

Keep in mind that IE can only determine the MIME type of a file based on its extension when a handler application for that MIME type (e.g. Adobe Reader) is installed on the system and creates the mapping inside the registry's HKEY_CLASSES_ROOT registry hive. If no mapping exists in the registry, then IE has no way to know what MIME type the file is.

Among 20 GB of freshly installed Windows there was no space to put file tool

like image 195
sergeykish Avatar answered Oct 02 '22 22:10

sergeykish