0

As per my understanding, when I upload .xlsx file from pc which has installed MS Excel it gives me type= application/vnd.openxmlformats-officedocument.spreadsheetml.sheet and when I upload same file from pc which has not MS Excel installed it gives me type="". The following jquery code checks twice in if condition as inputFile.type="application/"

 $("#btnUpload").change(function () {
        var inputFile = $(this).get(0).files[0];
        if (inputFile != undefined || inputFile != null) {
            if (inputFile.type == ".csv" || inputFile.type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" || inputFile.type == "application/vnd.ms-excel") {
                $("#uploadedFileName").html(inputFile.name)
            } else {
                errorToast("Please select valid file format");
            }
        } else {
            errorToast("Please select file");
        }
    });

Please help me out with the role of application/ prefix. or correct my understanding.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Vaibhav Deshmukh
  • 183
  • 1
  • 11

1 Answers1

1

you are talking about different MIME types. Here is a complete list of mime types: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types

"application/" has different options as you can see. If the PC does not have any excel installed it should not affect the file type you are talking about.

Here is an other question that should help you out: JS and type.match as file mime type - need advice

Richárd Baldauf
  • 1,068
  • 2
  • 10
  • 24