SkillAgentSearch skills...

Filetobase64

File to base64 using FileReader

Install / Use

/learn @miguelmota/Filetobase64
About this skill

Quality Score

0/100

Supported Platforms

Universal

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

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

View on GitHub
GitHub Stars5
CategoryDevelopment
Updated3y ago
Forks2

Languages

JavaScript

Security Score

70/100

Audited on Jan 28, 2023

No findings