Created
November 15, 2013 08:22
-
-
Save davidbarredo/7480937 to your computer and use it in GitHub Desktop.
Image data on change input file type
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
var url = window.URL || window.webkitURL; | |
// Change inputFileID with your own | |
document.getElementById("inputFileID").onchange = function() { | |
if ( this.disabled ) { | |
// File upload not allowed | |
console.log( 'Your browser does not support File upload.' ); | |
} else { | |
var fileChosen = this.files[0]; | |
var image = new Image(); | |
image.onload = function() { | |
// Do something with the data | |
console.log( 'Width:'+this.width +' Height:'+ this.height+' '+ Math.round(fileChosen.size/1024)+'KB' ); | |
}; | |
image.onerror = function() { | |
// Error | |
console.log( 'Not a valid file type: '+ fileChosen.type ); | |
}; | |
image.src = url.createObjectURL(fileChosen); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment