Skip to content

Instantly share code, notes, and snippets.

Created Dec 28, 2016
What would you like to do?
simple file upload to base64 string
<label for="filePicker">Choose or drag a file:</label><br>
<input type="file" id="filePicker">
<textarea id="base64str" cols="50" rows="15"></textarea>
var fileHandler = function(evt) {
var files =;
var file = files[0];
if (files && file) {
var reader = new FileReader();
reader.onload = function(readerEvt) {
var binaryString =;
document.getElementById("base64str").value = btoa(binaryString);
document.getElementById('filePicker').addEventListener('change', fileHandler, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment