Javascript Project to Convert Local Image File to Data URI String in Browser

 

 

index.html

 

 

<textarea name="results"></textarea><br />
<input type="file" name="image_file" id="image_file" />
<script>
document.querySelector('#image_file').onchange = function(){
  var reader = new FileReader();
  reader.onloadend = function () {
    document.querySelector('textarea').value = reader.result;
  }
  reader.readAsDataURL(this.files[0]);
};
</script>

Leave a Reply