filetobase64

0.0.4 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i filetobase64

Weekly Downloads

21

Version

0.0.4

License

MIT

Last publish

Collaborators

  • miguelmota