Skip to content

Instantly share code, notes, and snippets.

@arnellebalane
Created August 24, 2014 03:36
Show Gist options
  • Save arnellebalane/b41ebbb747999d9e0366 to your computer and use it in GitHub Desktop.
Save arnellebalane/b41ebbb747999d9e0366 to your computer and use it in GitHub Desktop.
using the FileReader api
// only files that are added through a file input field can be read
var input = document.querySelector('input[type="file"]');
// can also handle multiple files, but i'll just use one here
var file = input.files[0];
var reader = new FileReader();
reader.onload = function(e) {
var data = e.target.result;
// do anything with data, which is the file that has been read
}
reader.readAsDataURL(file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment