filetobase64
v0.0.4
Published
File to base64
Downloads
17
Readme
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
bower install filetobase64
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(e) {
var file = e.currentTarget.files[0];
fileToBase64(file, function(base64) {
console.log(base64); // iVBORw0KGgoAAAANSUhEUgAAADY...
output.src = 'data:' + file.type + ';base64,' + base64;
});
}, false);
License
MIT