Created
August 24, 2014 03:36
-
-
Save arnellebalane/b41ebbb747999d9e0366 to your computer and use it in GitHub Desktop.
using the FileReader api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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