0

when user uploads a file, I want to show preview of the document but i can't find the way how to do it.

what I am doing is

<input  id="FileFrame" type="file" ng-file-select="onFileSelect($files)" ng-click="resetInputFile()">

In my controller read the file as readAsBinaryString

    var fileReaders = new FileReader();
        fileReaders.readAsBinaryString($files[i]);
            var loadFile = function(fileReaders, index) {
            fileReaders.onload = function(e) {
            $timeout(function() {
            $scope.dataUrlss = e.target.result;
            });
        }
    }(fileReaders, i);

Im giving dataUrlss to iframe, but it won't works..

<iframe ng-show="dataUrlss != null" src="about:blank" style="width: 90%; height: 300px" name="internal"></iframe>

Thanks..

I added new code like

   var doc = document.getElementById('FileFrame').contentWindow.document;
    doc.open();
    doc.write($scope.dataUrlss);
    doc.close();

but it prints in different format.

iframe output

User4567
  • 1,005
  • 1
  • 12
  • 27
  • Shouldn't you be reading those files and then write content into iframe instead of assigning it to src? – maurycy Jun 20 '14 at 08:14
  • thanks for suggestion, i tried but in the iframe it displays in the format [json File] and the code is var doc = cument.getElementById('FileFrame').contentWindow.document; doc.open(); doc.write($scope.dataUrlss); doc.close(); – User4567 Jun 23 '14 at 04:49
  • @Chinnu: What kind of files ? Text files or other types ? – gkalpak Jun 23 '14 at 12:57
  • @ExpertSystem Its a xlx files. – User4567 Jun 24 '14 at 09:24
  • @Chinnu: Then you can't just preview the document by outputting binary content in an iframe. First of all the user's browser should be able to show XLSX files (which most browsers aren't configed to do). I don't think previewing an XLSX document will be as staight-forward as you've hoped (if at all possible in a reliable way). – gkalpak Jun 24 '14 at 10:23

0 Answers0