p5.dom createFileInput() problem in FireFox

This code:

function setup() { var fileInput = createFileInput(getFile); } function getFile(file) { createImg(file.data); }

works fine in Chrome and Opera, but not in Firefox.

Error: ReferenceError: handleFileSelect is not defined

when i put the function declarations outside 'if' and 'for' in p5.dom.js, it works.

Code:

p5.prototype.createFileInput = function(callback, multiple) {

// Is the file stuff supported?
if (window.File && window.FileReader && window.FileList && window.Blob) {
  // Yup, we're ok and make an input file selector
  var elt = document.createElement('input');
  elt.type = 'file';

  // If we get a second argument that evaluates to true
  // then we are looking for multiple files
  if (multiple) {
    // Anything gets the job done
    elt.multiple = 'multiple';
  }

  // Now let's handle when a file was selected
  elt.addEventListener('change', handleFileSelect, false);

  //elt.addEventListener('change', handleFileSelect, false);
  return addElement(elt, this);
} else {
  console.log('The File APIs are not fully supported in this browser. Cannot create element.');
}
// Function to handle when a file is selected
// We're simplifying life and assuming that we always
// want to load every selected file
function handleFileSelect(evt) {
  // These are the files
  var files = evt.target.files;
  // Load each one and trigger a callback
  for (var i = 0; i < files.length; i++) {
    var f = files[i];
    var reader = new FileReader();
    reader.onload = makeLoader(f);
    // Text of data?
    // This should likely be improved
    if (f.type === 'text') {
      reader.readAsText(f);
    } else {
      reader.readAsDataURL(f);
    }
  }
  function makeLoader(theFile) {
    // Making a p5.File object
    var p5file = new p5.File(theFile);
    return function(e) {
      p5file.data = e.target.result;
      callback(p5file);
    };
  };
}

};

maybe there is another method?

Answers

  • edited March 2015

    I also confirm that in Cyberfox 35.0.1 the same "handleFileSelect is not defined" shows up!
    P.S.: Now also @ 36.0.4!

Sign In or Register to comment.