0.0.4 • Published 7 years ago

filetobase64 v0.0.4

Weekly downloads
9
License
MIT
Repository
github
Last release
7 years ago

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

0.0.4

7 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago