Fileupload Duplicating Files
Im making a simple test, just trying to upload a file, convert it to unsigned 8 array then log it on the console My code works perfectly but every time i push the button to upload
Solution 1:
Every time you click on the button, you're attaching a new .change event. This means they add up; two clicks = two listeners waiting for a file change.
Just move the .change event outside the .click event like this fiddle:
jQuery(function($) {
  $("#bid_uploadPicture").click(function() {
    event.preventDefault();
    document.getElementById("file").click();
  });
  var fr = newFileReader();
  $("#file").change(function() {
    fr.onload = imageIsLoaded;
    fr.readAsArrayBuffer(this.files[0]);
  });
});
functionimageIsLoaded(e) {
  data = newUint8Array(e.target.result)
  console.log(e.target.result);
}
Post a Comment for "Fileupload Duplicating Files"