m.nachury
m.nachury

Reputation: 992

Firefox add wrong extention to OpenXML spreadsheet file with supposed good MIME type

I'm creating a webpage that uses the script FileSaver.js (https://github.com/eligrey/FileSaver.js) to make the user download an OpenXML file.

Here is the function that download the file using Ajax, decompress it and then make the user download it:

function dlExcel(){
    var bOk = true;
    try {
        var isFileSaverSupported = !!new Blob;
    } catch (e) {
    bOk = false;
        alert("Votre navigateur ne supporte pas l'expore des fichiers excel, veuillez le metre à jour.");
    }
    var oReq = new XMLHttpRequest();
    oReq.open("GET", "AJXExcel.aspx", true);
    oReq.responseType = "arraybuffer";

    oReq.onload = function (oEvent) {
        if (oReq.status == 503){
            alert("Une erreur est survenue");
        }
        else if (oReq.status == 208){
            alert("Le fichier demandé comporte trop de ligne, veuillez affiner votre recherche à l'aide des filtres poposé");
        }else{
            var arrayBuffer = new Uint8Array(oReq.response);
            var gunzip = new Zlib.Gunzip(arrayBuffer);
            var plain = gunzip.decompress();
            var blob = new Blob([plain], {
                "type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            });
            if(oReq.status == 206)
                alert("Le fichier généré comportait trop de lignes, il a donc été tronqué");
            saveAs(blob,"resultats.xml");
        }
        document.getElementById("ctl00_ctl00_MenuContentPlaceHolder_MainContentPlaceHolder_loading").style.display = "none";
        document.getElementById("ctl00_ctl00_MenuContentPlaceHolder_MainContentPlaceHolder_param").style.display = "block";
    }
    if (bOk){
        oReq.send(null);
    }
}

I have tried many MIME Type and extension and they either open using the XML Editor (the soft from office that determines with soft to use to open the XML File) or directly with Excel (which I want) but Firefox adds a .xls after the .xml so that make a file.xLs.xml that excel refuse to open.

I wasn't able to find a similar issue on the web, so if I could at least have an idea on what's causing it I'll be grateful!

I was thinking of the Windows registry at first, but the issue appears to only happen on Firefox so.

Upvotes: 1

Views: 139

Answers (1)

r.forcefield
r.forcefield

Reputation: 36

I found a similar post here Firefox add wrong extention to OpenXML spreadsheet file with supposed good MIME type.

It looks like a reported bug.

Although this glitch doesn't seem confirmed yet.

But you cant try with the mime type vdn.application/xml.

Upvotes: 2

Related Questions