jeudi 21 février 2019

download doc or pdf using java rest api

Downloading a doc or pdf file from server doesn't work in IE 11 and firefox. It works in Chrome. Please help.

I am calling the below function from a javascript.

function downloadFile(urlToSend) {
                    var req = new XMLHttpRequest();

                    req.open("GET", urlToSend, true);
                    req.responseType = "blob";

                    req.onload = function (event) {
                       
                        var blob = req.response;

                        var fileName = 'sample.doc';
                       
                        var link = document.createElement('a');
                        link.href = window.URL.createObjectURL(blob);
                        link.download = fileName;
                        link.click();


                    };

                    req.send();
                }



Aucun commentaire:

Enregistrer un commentaire