Filetobase64
File to base64 using FileReader
Install / Use
/learn @miguelmota/Filetobase64README
File to Base64
Takes in a File object and returns a base64 string with the help of the FileReader API.
Demo
https://lab.miguelmota.com/filetobase64
Install
npm install filetobase64
Usage
<input type="file" id="file" accept="image/*">
<img id="output">
<script src="filetobase64.js"></script>
var fileInput = document.getElementById('file')
var output = document.getElementById('output')
fileInput.addEventListener('change', function(event) {
var file = event.currentTarget.files[0]
fileToBase64(file, function(base64) {
console.log(base64) // iVBORw0KGgoAAAANSUhEUgAAADY...
output.src = 'data:' + file.type + ';base64,' + base64
})
}, false)
License
MIT
