0

tengo un problema, lo que pasa es que no se realiza la descarga de archivos cuando ejecuto la aplicación web en ie11. Las funciones son las siguientes:

Descarga múltiple

$scope.downloadAll = function () {
    angular.forEach($scope.listFiles, function(fileDownload) {
        if(fileDownload.status == 'Completado'){
            var theAnchor = $('<a />')
            .attr('href', fileDownload.data)
            .attr('download', fileDownload.nameOut)
            // Firefox does not fires click if the link is
            // outside
            // the DOM
            .appendTo('body');
            theAnchor[0].click();
            theAnchor.remove();
        }               
    });
}

Descarga individual

$scope.downloadFile = function (index) {
    var file = $scope.listFiles[index];
    if(file.status == 'Completado'){
        var theAnchor = $('<a />')
        .attr('href', file.data)
        .attr('download', file.nameOut)
        // Firefox does not fires click if the link is
        // outside
        // the DOM
        .appendTo('body');
        theAnchor[0].click();
        theAnchor.remove();
    }
}

/**

No sé si alguien me pueda ayudar? funciona correctamente en Chrome y Firefox.

2
  • Y que error aparece? el 29 may. 2017 a las 16:27
  • Se muestra el mensaje de "Do you want to allow this website to open an app on your computer?". Una vez que le doy Allow se muestra solamente la tienda.
    – Carmen A.
    el 29 may. 2017 a las 16:31

1 respuesta 1

0

La solución sería la siguiente:

 $scope.downloadAll = function () {
    angular.forEach($scope.listFiles, function(file) {
        if(file.status == 'Completado'){
            var pdfDownload = document.createElement("a");
            document.body.appendChild(pdfDownload);
            var fileBlob = base64toBlob(file.data.split(",")[1],file.type);
            if (navigator.appVersion.toString().indexOf('.NET') > 0)
            { // for IE browser
                window.navigator.msSaveBlob(fileBlob, file.nameOut);
            } else 
            { // for other browsers
                var fileURL = window.URL.createObjectURL(fileBlob);
                pdfDownload.href = fileURL;
                pdfDownload.download = file.nameOut;
                pdfDownload.click();      
            }
        }               
    });
}

$scope.downloadFile = function (index) {
    var file = $scope.listFiles[index];
    if(file.status == 'Completado'){
        var pdfDownload = document.createElement("a");
        document.body.appendChild(pdfDownload);
        var fileBlob = base64toBlob(file.data.split(",")[1],file.type);
        if (navigator.appVersion.toString().indexOf('.NET') > 0)
        { // for IE browser
            window.navigator.msSaveBlob(fileBlob, file.nameOut);
        } else 
        { // for other browsers
            var fileURL = window.URL.createObjectURL(fileBlob);
            pdfDownload.href = fileURL;
            pdfDownload.download = file.nameOut;
            pdfDownload.click();      
        }
    }
}

/***
 * Convertir Base64 a Blob
 */
function base64toBlob(base64Data, contentType) {
    contentType = contentType || '';
    var sliceSize = 1024;
    var byteCharacters = atob(base64Data);
    var bytesLength = byteCharacters.length;
    var slicesCount = Math.ceil(bytesLength / sliceSize);
    var byteArrays = new Array(slicesCount);

    for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
        var begin = sliceIndex * sliceSize;
        var end = Math.min(begin + sliceSize, bytesLength);

        var bytes = new Array(end - begin);
        for (var offset = begin, i = 0 ; offset < end; ++i, ++offset) {
            bytes[i] = byteCharacters[offset].charCodeAt(0);
        }
        byteArrays[sliceIndex] = new Uint8Array(bytes);
    }
    return new Blob(byteArrays, { type: contentType });
}

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.