FileReader reads as DataUrl

I am working on this app in the Chrome App Store. Obviously, the file API has changed, so I had to implement FileReader to get the local URL of the file that is being deleted to the page.

function drop(evt) {

    v = evt.target.id;

    evt.stopPropagation();
    evt.preventDefault();

    var files = evt.dataTransfer.files; // FileList object.

    var f = files[0];

    var reader = new FileReader();

          // Closure to capture the file information.
          reader.onload = (function(theFile) {
            return function(e) {
              document.getElementById(v).src = e.target.result;
            };
          })(f);

   reader.readAsDataURL(f);
}

What I'm trying to do is load the URL of the song that was deleted on the page into the HTML5 tag attribute src. I cannot understand what I am doing wrong with this drop function.

Does anyone have any ideas?

+3
source share
2 answers

. API- . - . , -.

+2

, . ? drop ? , FileList

DnD ( src): http://www.html5rocks.com/tutorials/file/dndfiles/#toc-selecting-files-dnd

blobURL:

window.URL = window.URL || window.webkitURL;

function drop(evt) {
  ...
  var file = evt.dataTransfer.files[0];
  ...
  audio.src = window.URL.createObjectURL(file);
  audio.onload = function(e) {
    window.URL.revokeObjectURL(this.arc); // clean up
  };
}
+1

All Articles