Skip to content

Instantly share code, notes, and snippets.

@fefz
Last active May 20, 2017 15:11
Show Gist options
  • Save fefz/90d13c8f85a62a2fe24dffb6f780708d to your computer and use it in GitHub Desktop.
Save fefz/90d13c8f85a62a2fe24dffb6f780708d to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/kisubeq
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style>
p{
word-break: break-all;
}
</style>
</head>
<body>
<div id="uploadForm">
<input id="file" type="file"/>
</div>
<br>
<hr>
<p id="res"></p>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script id="jsbin-javascript">
fileReader = new FileReader();
fileReader.onload = function (e) {
var dataURL = e.target.result;
var res = dataURL.slice(dataURL.indexOf(',')+1);
$('#res').text(res);
}
fileReader.addEventListener('load', function () {
console.log('file loaded');
})
fileReader.addEventListener('error', function () {
console.log('file load error');
})
$('#file').on('change',function(){
var file = $('#file')[0].files[0];
fileReader.readAsDataURL(file);
})
</script>
<script id="jsbin-source-javascript" type="text/javascript">
fileReader = new FileReader();
fileReader.onload = function (e) {
var dataURL = e.target.result;
var res = dataURL.slice(dataURL.indexOf(',')+1);
$('#res').text(res);
}
fileReader.addEventListener('load', function () {
console.log('file loaded');
})
fileReader.addEventListener('error', function () {
console.log('file load error');
})
$('#file').on('change',function(){
var file = $('#file')[0].files[0];
fileReader.readAsDataURL(file);
})</script></body>
</html>
fileReader = new FileReader();
fileReader.onload = function (e) {
var dataURL = e.target.result;
var res = dataURL.slice(dataURL.indexOf(',')+1);
$('#res').text(res);
}
fileReader.addEventListener('load', function () {
console.log('file loaded');
})
fileReader.addEventListener('error', function () {
console.log('file load error');
})
$('#file').on('change',function(){
var file = $('#file')[0].files[0];
fileReader.readAsDataURL(file);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment