Created
September 24, 2014 08:56
-
-
Save xiel/4f9030ce775614902e82 to your computer and use it in GitHub Desktop.
FileReader Error // source http://jsbin.com/yucavaxiyufi/6
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>FileReader Error</title> | |
</head> | |
<body> | |
<form> | |
<input id="fileInput" type="file" accept-"image/*"> | |
</form> | |
<div id="output"></div> | |
<script id="jsbin-javascript"> | |
var fileInput = document.getElementById('fileInput'); | |
var output = document.getElementById('output'); | |
fileInput.onchange = function() { | |
window.console.warn("hi"); | |
var files = fileInput.files; | |
if (files && files[0]) { | |
var file = files[0]; | |
var fileReader = new FileReader(); | |
fileReader.onload = function(e) { | |
output.innerHTML = "Success! length: " + e.target.result.length; | |
}; | |
fileReader.onerror = function(e) { | |
output.innerHTML = "Failure with error code: " + e.target.error.code; | |
}; | |
fileReader.readAsBinaryString(file); | |
} | |
}; | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript"> | |
var fileInput = document.getElementById('fileInput'); | |
var output = document.getElementById('output'); | |
fileInput.onchange = function() { | |
window.console.warn("hi"); | |
var files = fileInput.files; | |
if (files && files[0]) { | |
var file = files[0]; | |
var fileReader = new FileReader(); | |
fileReader.onload = function(e) { | |
output.innerHTML = "Success! length: " + e.target.result.length; | |
}; | |
fileReader.onerror = function(e) { | |
output.innerHTML = "Failure with error code: " + e.target.error.code; | |
}; | |
fileReader.readAsBinaryString(file); | |
} | |
};</script></body> | |
</html> |
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 fileInput = document.getElementById('fileInput'); | |
var output = document.getElementById('output'); | |
fileInput.onchange = function() { | |
window.console.warn("hi"); | |
var files = fileInput.files; | |
if (files && files[0]) { | |
var file = files[0]; | |
var fileReader = new FileReader(); | |
fileReader.onload = function(e) { | |
output.innerHTML = "Success! length: " + e.target.result.length; | |
}; | |
fileReader.onerror = function(e) { | |
output.innerHTML = "Failure with error code: " + e.target.error.code; | |
}; | |
fileReader.readAsBinaryString(file); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment