-
-
Save jochemstoel/b542766241b292205450ee74c38dbaf2 to your computer and use it in GitHub Desktop.
Upload and file and convert it into a base64 data url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function uploadAndConvertToBase64DataURL(callback) { | |
if (!document.getElementById("B64DURL_UL")) { | |
var input = document.createElement("input"); | |
input.id = "B64DURL_UL"; | |
input.style.display = "none"; | |
input.type = "file"; | |
document.body.appendChild(input); | |
} | |
var input = document.getElementById("B64DURL_UL"); | |
input.addEventListener("change", function (e){ | |
var file = e.target.files[0]; | |
var reader = new FileReader(); | |
reader.onload = function (e) { | |
callback(e.target.result); | |
}; | |
reader.readAsDataURL(file); | |
}, false); | |
input.click(); | |
} | |
// uploadAndConvertToBase64DataURL(function(dataURL){...}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment