Skip to content

Instantly share code, notes, and snippets.

@jherrlin
Created February 24, 2016 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jherrlin/b0b45736a32417a0d3cc to your computer and use it in GitHub Desktop.
Save jherrlin/b0b45736a32417a0d3cc to your computer and use it in GitHub Desktop.
<script type="text/javascript">
function loadImageFileAsURL()
{
var filesSelected = document.getElementById("image").files;
var base64 = document.getElementById("base64");
if (filesSelected.length > 0)
{
var fileToLoad = filesSelected[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var textAreaFileContents = document.getElementById
(
"textAreaFileContents"
);
textAreaFileContents.innerHTML = fileLoadedEvent.target.result;
base64.value = fileLoadedEvent.target.result;
};
fileReader.readAsDataURL(fileToLoad);
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment