Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8197790

FileReader does not work

XMLWordPrintable

    • web
    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_172-ea"
      Java(TM) SE Runtime Environment (build 1.8.0_172-ea-b03)
      Java HotSpot(TM) 64-Bit Server VM (build 25.172-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 and 10

      A DESCRIPTION OF THE PROBLEM :
      I have reported the bug JDK-8194265. So you provide the the early build 172, i test it. And I am really disappointed. Yes, the crash is fixed, but we don't see the file content.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See also html5rocks/tutorials/file/dndfiles
      See Example: Slicing a file.

      or

      http://papaparse.com/demo

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The callback reader.result should return the file result in callbackhandler reader.onload.
      ACTUAL -
      Error. I don't see any alert message in one of the callback handlers.
      Currently we don't see the result of reading the file.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      <!DOCTYPE html>
      <html>
      <body>

      <p id="demo"></p>



      <style>
        #progress_bar {
          margin: 10px 0;
          padding: 3px;
          border: 1px solid #000;
          font-size: 14px;
          clear: both;
          opacity: 0;
          -moz-transition: opacity 1s linear;
          -o-transition: opacity 1s linear;
          -webkit-transition: opacity 1s linear;
        }
        #progress_bar.loading {
          opacity: 1.0;
        }
        #progress_bar .percent {
          background-color: #99ccff;
          height: auto;
          width: 0;
        }
      </style>


      <input type="file" id="files" name="file" />
      <button onclick="abortRead();">Cancel read</button>
      <div id="progress_bar"><div class="percent">0%</div></div>

      <script>
      var w = window.innerWidth
      || document.documentElement.clientWidth
      || document.body.clientWidth;

      var h = window.innerHeight
      || document.documentElement.clientHeight
      || document.body.clientHeight;


        var reader;
        var progress = document.querySelector('.percent');

        function abortRead() {
          reader.abort();
        }

        function errorHandler(evt) {
          alert('error')
        }

        function updateProgress(evt) {
          alert('updareprof')
        }
       
       function onInitFs(fs) {
        console.log('Opened file system: ' + fs.name);
      }


        function handleFileSelect(evt) {
        try {
          var files = evt.target.files;
          var f = files[0];
      alert(f.size);
          // Reset progress indicator on new file selection.
          progress.style.width = '0%';
          progress.textContent = '0%';
      alert(Object.getOwnPropertyNames(FileReader))
      console.log(Object.getOwnPropertyNames(Math));
          console.log('File Selected');
      alert(window.FileReader);
      alert('creating reader')
          reader = new window.FileReader();
      alert(Object.getOwnPropertyNames(reader))
          reader.onerror = errorHandler;

          reader.onprogress = updateProgress;

          reader.onabort = function(e) {
            alert('File read cancelled');
          };

          reader.onloadstart = function(e) {
          console.log('onloadstart');
          };

          reader.onload = function(e) {
           alert('loading');
      alert(reader.result);
          }
      reader.onloadend = function(e) {
            alert('end');
      alert(reader.result);
          }


          // Read in the image file as a binary string.
      alert('before ');
      console.log('a1');
      alert(f.name);
      console.log('before readyState');
      alert(reader.readyState);
      alert("Vor Read text");
          reader.readAsText(f);
      alert("Nach Read text");

      } catch(err) {
      alert(err.message);
      }
        }


      console.log('After Load');

      if (window.File && window.FileReader && window.FileList && window.Blob) {
        alert('The File APIs is supported');
      } else {
        alert('The File APIs are not fully supported in this browser.');
      }
      console.log('After check');
      if(window.requestFileSystem) {
      alert('can request fs')
      }
      if(window.webkitRequestFileSystem) {
      alert('can request webkit fs')
      }
      window.onerror = function(e) {
           alert('window error');
       }
      alert('before requesting')
      window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
      console.log('request FS');
      <!--
      //var fs = window.requestFileSystem(window.TEMPORARY, 5*1024*1024 /*5MB*/, onInitFs, errorHandler);
      //alert (fs.name);
      //alert (fs.root);
      -->
      //window.webkitStorageInfo.requestQuota(PERSISTENT, 1024*1024, function(grantedBytes) {
      // console.log('request persistnet')
      // window.requestFileSystem(PERSISTENT, grantedBytes, onInitFs, errorHandler);
      //}, function(e) {
      // console.log('Error', e);
      //});

      var x = document.getElementById("demo");
      x.innerHTML = "Browser inner window width: " + w + ", height: " + h + ".";
      document.getElementById('files').addEventListener('change', handleFileSelect, false);
      </script>

      </body>
      </html>

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      there is no workaround.

      SUPPORT :
      YES

            mbilla Murali Billa
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: