Skip to content

Instantly share code, notes, and snippets.

@SpencerCooley
Created September 8, 2014 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SpencerCooley/a2dc15fa8024c8fcc1d3 to your computer and use it in GitHub Desktop.
Save SpencerCooley/a2dc15fa8024c8fcc1d3 to your computer and use it in GitHub Desktop.
function renderImage(file){
var reader = new FileReader();
reader.onload = function(event){
the_url = event.target.result
$('#some_container_div').html("<img src='"+the_url+"' />")
}
//when the file is read it triggers the onload event above.
reader.readAsDataURL(file);
}
$( "#the-file-input" ).change(function() {
console.log(this.files)
//grab the first image in the FileList object and pass it to the function
renderImage(this.files[0])
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment