Show a blob in firefox

2

I'm trying to show a PDF on an HTML page but it does not show anything in firefox, I tried it in chrome and there it shows, using the following code.

   <div ng-if="downloaded">
       <object ng-bind="pdfcontent" data="{{pdfcontent}}" type="application/pdf" width="100%" height="800px">
          </object>
   </div>

In my controller I have the following code I get a base64 of a REST service and I convert it to blob assigning it to variable pdfcontent

        var blob = b64toBlob($scope.listaDocumentosById[index].docto, $scope.listaDocumentosById[index].tipo_docto);
        var fileURL = URL.createObjectURL(blob);
        $scope.pdfcontent = $sce.trustAsResourceUrl(fileURL);
        $scope.downloaded = true;

I tried to use the function window.open(fileURL); but only shows the pdf in chrome but not in firefox.

    
asked by David Medina 30.08.2017 в 23:32
source

1 answer

0

You can review link

// base64 string
var base64str = $scope.listaDocumentosById[index].docto;


var binary = atob(base64str.replace(/\s/g, ''));
var len = binary.length;
var buffer = new ArrayBuffer(len);
var view = new Uint8Array(buffer);
for (var i = 0; i < len; i++) {
    view[i] = binary.charCodeAt(i);
}

// Creamos el blob content-type "application/pdf"               
var blob = new Blob( [view], { type: "application/pdf" });
var url = URL.createObjectURL(blob);
window.open(url);
    
answered by 22.02.2018 в 04:07