13

I am trying to display a binary file using the method suggested in this post AngularJS: Display blob (.pdf) in an angular app. This is working nicely in Chrome and FF, but IE 11 is giving me "Error: Access Denied". Does anyone know if it has something to do with the Blob object and can point me in the right direction? Here is my js code:

$http.get(baseUrl + apiUrl, { responseType: 'arraybuffer' })
          .success(function (response) {                  
             var file = new Blob([response], { type: 'application/pdf' });
             var fileURL = URL.createObjectURL(file);
             $scope.pdfContent = $sce.trustAsResourceUrl(fileURL);
           })
           .error(function () {                        
           });

and my html:

<div ng-controller="PDFController" class="modal fade" id="pdfModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
    <div class="modal-content" onloadstart="">
        <object data="{{pdfContent}}"  type="application/pdf" style="width:100%; height:1000px" />
    </div>
</div>

jymuk
  • 139
  • 1
  • 6
  • Workaround: I finally used [FileSaver.js](https://github.com/eligrey/FileSaver.js/), but I would still appreciate it if anyonw can tell me why the above mentioned technique isn't working in IE 11... – jymuk Oct 06 '14 at 07:24
  • 1
    I am having this issue as well, did you ever get it working without the FileSaver.js? – Madhatter5501 Oct 29 '14 at 20:43
  • No I didn't unfortunately... – jymuk Nov 03 '14 at 09:25
  • I know its late but I have same problem. Can you provide some info to display the pdf from blob? – Rana_S Nov 07 '15 at 03:05
  • Possible duplicate of [IE9 - Error in function : 'ArrayBuffer' is undefined ReferenceError: 'ArrayBuffer' is undefined](http://stackoverflow.com/questions/26103091/ie9-error-in-function-arraybuffer-is-undefined-referenceerror-arraybuffe) – Paul Sweatte Feb 18 '16 at 00:34
  • For more details and a reference implementation in React JS, please refer https://stackoverflow.com/a/41215607/2556796 – roray Jul 29 '17 at 20:00

1 Answers1

8

IE 11 blocks display of blob, you need to use the following:

                    var byteArray = new Uint8Array(someByteArray);
                var blob = new Blob([byteArray], { type: 'application/pdf' });
                if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                    window.navigator.msSaveOrOpenBlob(blob);
                }
                else {
                    var objectUrl = URL.createObjectURL(blob);
                    window.open(objectUrl);
                }
Rani Radcliff
  • 4,856
  • 5
  • 33
  • 60